summaryrefslogtreecommitdiffstats
path: root/cmsg.h
blob: e1e0e80d84f9385b244a4a597b71732f1feca4c9 (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
/*  Copyright 2008,2009,2010 Edwin Eefting (edwin@datux.nl) 

    This file is part of Synapse.

    Synapse is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Synapse is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Synapse.  If not, see <http://www.gnu.org/licenses/>. */













#ifndef CMSG_H
#define CMSG_H
#include <string>
#include <map>
#include <boost/any.hpp>
#include <boost/variant.hpp>
#include <boost/shared_ptr.hpp>

#include "cvar.h"
//#include "cmessageman.h"





/*
typical route of a cmsg object

1. Sendmessage is called with a shared_ptr to a Cmsg object:
   [Cmsg object] -smart_ptr-> Sendmessage() 
 	
2. This creates one or more Ccalls that point to it:
           [Ccall objects]  -shared_ptr->  [Cmsg object]

3. A operator() thread fetches a Iterator to a call object:
           operator() -iterator-> [Ccall object] --shared_ptr-> [Cmsg object]

4. The operator calls the apropriate handler with a reference to the message object:
     [Cmsg object] -reference-> soHander() 

5. The Ccall objects are deleted after the operators() are done:
    *poof* shared_ptr automaticly deletes [Cmsg object] after everyone is one. 
    INCLUDING the original sender of the message.



*/


/**
	@author 
*/

namespace synapse
{
	using namespace std;


	class Cmsg : public Cvar  {
	public:
		Cmsg();
		~Cmsg();
		int src;
		int dst;
		string event;

		//this function is only implemented in the .so object module
		//so if you use it in the core you will get linker errors :)
		void send(int cookie=0);
		void returnError(string description);
		void returnWarning(string description);
		bool returnIfOtherThan(char * keys, ...);

		//json stuff
		void toJson(string & jsonStr);
		void fromJson(string & jsonStr);

		//things to make Cvar usage easier
		Cvar & operator=(Cvar & var);

	};

	typedef shared_ptr<Cmsg> CmsgPtr;

}

typedef synapse::Cmsg Cmsg;

#endif