summaryrefslogtreecommitdiff
path: root/tools/ivytestready.c
blob: b3acd7bd8da96d86b95e8c370c0771a647271487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 *	Ivy perf mesure le temp de round trip
 *
 *	Copyright (C) 1997-2004
 *	Centre d'Études de la Navigation Aérienne
 *
 * 	Main and only file
 *
 *	Authors: François-Régis Colin <fcolin@cena.fr>
 * 	         Yannick Jestin <jestin@cena.fr>
 *
 *	Please refer to file version.h for the
 *	copyright notice regarding this software
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#ifdef __MINGW32__
#include <regex.h> 
#include <getopt.h>
#endif
#else
#include <sys/time.h>
#include <unistd.h>
#ifdef __INTERIX
extern char *optarg;
extern int optind;
#endif
#endif


#include "Ivy/ivysocket.h"
#include "Ivy/ivy.h"
#include "Ivy/timer.h"
#include "Ivy/ivyloop.h"
#define MILLISEC 1000.0

const char * me = "A";
const char * other = "B";
char ready_message[1000] = "A ready";
char ready_bind[1000] = "^B ready";

void Ready (IvyClientPtr app, void *user_data, int argc, char *argv[])
{
	char *name = IvyGetApplicationName( app );
	int count = IvySendMsg ("are you there %s",name);
	printf("Application %s received '%s' from %s sent question 'are you there %s'= %d\n", me, ready_bind, name, name, count);
}

void Question (IvyClientPtr app, void *user_data, int argc, char *argv[])
{
	char *name = IvyGetApplicationName( app );
	int count = IvySendMsg ("yes i am %s",me);
	printf("Application %s Reply to %s are you there = %d\n", me, name, count);
	
}
void Reply (IvyClientPtr app, void *user_data, int argc, char *argv[])
{
	char *name = IvyGetApplicationName( app );
	printf("Application %s Reply to our question! %s\n", name, argv[0]);
	
}

void binCB( IvyClientPtr app, void *user_data, int id, const char* regexp,  IvyBindEvent event ) 
{
	char *app_name = IvyGetApplicationName( app );
	switch ( event )
	{
	case IvyAddBind:
		printf("%s receive Application:%s bind '%s' ADDED\n", me, app_name, regexp );
		//if ( *me == 'A' ) usleep( 200000 ); // slowdown sending of regexp
		break;
	case IvyRemoveBind:
		printf("%s receive Application:%s bind '%s' REMOVED\n", me, app_name, regexp );
		break;
	case IvyChangeBind:
		printf("%s receive Application:%s bind '%s' CHANGED\n", me, app_name, regexp );
		break;
	case IvyFilterBind:
		printf("%s receive Application:%s bind '%s' FILTRED\n", me, app_name, regexp );
		break;

	}
}
int main(int argc, char *argv[])
{
	
	/* Mainloop management */
	if ( argc > 1 )
	{
	 me = "B" ;
	 other = "A";
	 strcpy( ready_message, "B ready");
	 strcpy( ready_bind, "^A ready");
	}

	IvyInit (me, ready_message, NULL,NULL,NULL,NULL);
	IvySetBindCallback( binCB, 0 ),
	IvyBindMsg (Ready, NULL, ready_bind);
	IvyBindMsg (Question, NULL, "^are you there %s",me);
	IvyBindMsg (Reply, NULL, "^(yes i am %s)",other);
	 
	IvyStart (0);

	
	IvyMainLoop ();
	return 0;
}