summaryrefslogtreecommitdiff
path: root/Bus/Ivy/IvyCbindings.cxx
blob: 8876bbfe529aa2540a222bc994e2a667f842eb50 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

#include "IvyStdAfx.h"
#include <stdarg.h>
#include "Ivy.h"
#include "IvyApplication.h"

#include "IvyCbindings.h"

static Ivy *bus = NULL;

// application callback wrappers
IvyCApplicationCallback app_cb = NULL;
void * app_user_data = NULL;
void app_conn( IvyApplication *app )
{
	(*app_cb)(app, app_user_data, IvyApplicationConnected );
}
void app_discon( IvyApplication *app )
{
	(*app_cb)(app, app_user_data, IvyApplicationDisconnected );
}

void IvyInit(
	 const char *AppName,		/* nom de l'application */
	 const char *ready,		/* ready Message peut etre NULL */
	 IvyCApplicationCallback callback, /* callback appele sur connection deconnection d'une appli */
	 void *data,			/* user data passe au callback */
	 IvyCDieCallback die_callback,	/* last change callback before die */
	 void *die_data	)		/* user data */
{
	bus = new Ivy(AppName, ready, BUS_APPLICATION_CALLBACK(app_conn,app_discon) );
}
/* filtrage des regexps */
void IvySetFilter( int argc, const char **argv)
{
	bus->SetFilter( argc, argv );
}

void IvyStart (const char* domain)
{
	bus->start(domain);
}
void IvyStop ()
{
	bus->stop();
}

/* query sur les applications connectees */
const char *IvyGetApplicationName( IvyClientPtr app )
{
	return ((IvyApplication*)app)->GetName();
}
const char *IvyGetApplicationHost( IvyClientPtr app )
{
	ivy::string host;
	UINT port;
	((IvyApplication*)app)->GetPeerName(host,port);
	return host.c_str();
}
IvyClientPtr IvyGetApplication( char *name )
{
	return NULL;
}
const char *IvyGetApplicationList()
{
	return "Not yiet implemented";
}
const char **IvyGetApplicationMessages( IvyClientPtr app)
{
	return NULL;
}

MsgRcvPtr IvyBindMsg( IvyCMsgCallback callback, void *user_data, const char *fmt_regexp, ... )
{
	int count;
	char buf_regexp[2048];
	va_list  args;
	va_start( args, fmt_regexp );
	_vsnprintf_s( buf_regexp, sizeof(buf_regexp), sizeof(buf_regexp)-1, fmt_regexp, args );
	count = bus->BindMsg(buf_regexp, BUS_CALLBACK( ((IvyMessageCallbackFunction::IvyMessageCallback_fun)callback), user_data ) );
	va_end( args );
	return count;
}
void IvyUnbindMsg( MsgRcvPtr id )
{
	bus->UnbindMsg( id );
}

/* emission d'un message d'erreur */
void IvySendError( IvyClientPtr app, int id, const char *fmt, ... )
{
	char buf[2048];
	va_list  args;
	va_start( args, fmt );
	_vsnprintf_s( buf, sizeof(buf), sizeof(buf)-1, fmt, args );
	((IvyApplication*)app)->SendMsg( IvyApplication::Error, id, buf );
	va_end( args );
}

/* emmission d'un message die pour terminer l'application */
void IvySendDieMsg( IvyClientPtr app )
{
	((IvyApplication*)app)->SendMsg( IvyApplication::Die, 0 );
}

/* emission d'un message retourne le nb effectivement emis */

int IvySendMsg( const char *fmt_message, ... )
{
	int count;
	char buf[2048];
	va_list  args;
	va_start( args, fmt_message );
	_vsnprintf_s( buf, sizeof(buf), sizeof(buf)-1, fmt_message, args );
	count = bus->SendMsg(buf);
	va_end( args );
	return count;
}

void IvyBindDirectMsg( IvyCMsgDirectCallback callback, void *user_data)
{
}
void IvySendDirectMsg( IvyClientPtr app, int id, char *msg )
{
}
void IvyMainLoop( void(*hook)(void) )
{
	Sleep( INFINITE );
}