summaryrefslogtreecommitdiff
path: root/Bus/Ivy/Ivy.h
blob: fe204f797590df3cc06c0d8afacd0d6f7059bdb9 (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
// Ivy.h: interface for the Ivy class.
//
//////////////////////////////////////////////////////////////////////


#pragma once

#ifdef  WIN32
#ifdef IVY_EXPORTS
class _declspec(dllexport) IvyWatcher;
class _declspec(dllexport) IvyApplication;
class _declspec(dllexport) Ivy;
class _declspec(dllexport) CThreadedSocket;
class _declspec(dllexport) CBufferedSocket;
#else
#pragma comment(lib,"Ivy.LIB" )
class _declspec(dllimport) IvyWatcher;
class _declspec(dllimport) IvyApplication;
class _declspec(dllimport) Ivy;
class _declspec(dllimport) CThreadedSocket;
class _declspec(dllimport) CBufferedSocket;
#endif
#endif

#ifdef IVY_USE_OWN_DATATYPES

#include "DataTypes.h"

#else

#include <string>
#include <list>
#include <vector>
#include <map>

namespace ivy =  std; 

#endif

#include "IvyCallback.h"


class Ivy  
{
	friend class IvyWatcher;

	friend class IvyApplication;

private:
	int regexp_id;
	unsigned int applicationPort;
	void SendSubscriptions(IvyApplication *app);
	bool synchronous;		// use Window Shink to made CB mono thread like
	IvyApplication * server;
	IvyWatcher * watcher;
	IvyDieCallback *die_callback;
	IvyDirectMessageCallback *direct_callback;
	IvyApplicationCallback *application_callback;
	IvyBindingCallback *binding_callback;
	/* list des adresses de broadcast */
	ivy::string domain;
	/* nom de l'appliction */
	ivy::string ApplicationName;
	/* Aplication Unique ID */
	ivy::string ApplicationID;
	/* liste des clients connectes */
	CRITICAL_SECTION  m_application_cs;
	typedef ivy::list<IvyApplication*> IvyApplicationList;
	IvyApplicationList applications;

	/* liste des souscriptions locale a emettre aux autres applications */
	ivy::vector<ivy::string> regexp_out;
	/* liste des callbacks a appeler */
	ivy::vector< IvyMessageCallback* > callbacks;
	
protected:
	void AddApplication( IvyApplication *app );
	void RemoveApplication( IvyApplication *app);

	bool CheckConnected( IvyApplication *app );
	void CallApplicationConnectedCallback( IvyApplication *app );
	void CallApplicationDisconnectedCallback( IvyApplication *app );
	void CallBindingAddCallback(IvyApplication * app, int id, const char * regexp);
	void CallBindingRemoveCallback(IvyApplication * app, int id, const char * regexp);
	void CallBindingFilterCallback(IvyApplication * app, int id, const char * regexp);
	bool CallDieCallback( IvyApplication *app, int id, const char *arg );
	void CallDirectMessageCallback( IvyApplication *app, int id, const char *arg );
	void CallMessageCallback( IvyApplication *app, int id, int argc, const char **argv );
	
	const char *GenApplicationUniqueIdentifier();
public:
 
	void SetBindCallback( IvyBindingCallback* bind_callback );
	void SetFilter( int argc, const char **argv );
	void SendDieMsg( IvyApplication *app );
	IvyApplication *GetApplication(const char *name);
	void SendDirectMsg( IvyApplication *app, int id, const char *message);
	void BindDirectMsg( IvyDirectMessageCallback *callback );
	int SendMsg( const char *message, ... );

	const char *GetDomain(const char *domainlist);
	unsigned int GetApplicationPort();
	int BindMsg( const char *regexp, IvyMessageCallback *cb );
	int BindMsg( IvyMessageCallback *cb, const char *regexp, ... );
	void UnbindMsg( int id );
	Ivy( const char *name, const char* ready, IvyApplicationCallback *callback, bool Synchronous = true );
	void start(const char *domain);
	void stop();
	virtual ~Ivy();
	
	/* message a emettre sur connection nouvelle application */
	ivy::string ready_message;
	

};