summaryrefslogtreecommitdiff
path: root/Ivy/IvyApplication.h
blob: cd9b123e82d0fc4afb317a30bf7eea29303f414c (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

#pragma once

// IvyApplication.h : header file
//
#include "BufferedSocket.h"
#include "Ivy.h"
#include "IvyBinding.h"

/////////////////////////////////////////////////////////////////////////////
// IvyApplication command target

class IvyApplication : public CBufferedSocket
{
// Attributes
public:


	typedef enum {

	Bye,			/* quit l'application ( non utilise ) */
	AddRegexp,		/* expression reguliere d'un client */
	Msg,			/* message reel */
	Error,			/* error message */
	DelRegexp,		/* Remove expression reguliere */
	EndRegexp,		/* end of the regexp list */
	StartRegexp,    /* debut des expressions */
	DirectMsg,		/* message direct a destination de l'appli */
	Die,			/* demande de terminaison de l'appli */
	Ping,			/* message de controle ivy */
	Pong			/* ivy doit renvoyer ce message à la reception d'un ping */

	}MsgType;

	
// Operations
public:
	IvyApplication(Ivy *bus);
	virtual ~IvyApplication();

// Overrides
public:
	BOOL SameApplication( IvyApplication *app );
	UINT remoteService;
	const char *GetName(void);
	inline Ivy *GetBus(void){ return bus;};
	int SendMsg( const char *message );
	void SendMsg( MsgType msg, int id, const char * arg = NULL);
	UINT Create();
	void OnReceive( char *line );
	void Create( const char * host, UINT &port, const char* name );
	virtual void OnAccept(int nErrorCode);
	virtual void OnClose(int nErrorCode);
protected:
	void SendReadyToPeer();
	
// Implementation
protected:
	int readyToSend;
	CRITICAL_SECTION  m_SendReadySection;

	ivy::string appname;
	bool AppConnectedCallbackCalled;
	Ivy *bus;
	/* compile */
	typedef ivy::map<int,IvyBinding *> Bindings;
	Bindings regexp_in;

	friend class Ivy;
};