-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcorbaComm.h
More file actions
96 lines (77 loc) · 2.8 KB
/
Copy pathcorbaComm.h
File metadata and controls
96 lines (77 loc) · 2.8 KB
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
#ifndef _CORBA_COMM_H
#define _CORBA_COMM_H
#include <string>
#include <vector>
namespace cc {
// for Command Provider only
// when clients invoke a 'execCmd()',
// command provider's callback will be invoked to provide data
//
typedef std::string (*CommandCallback_t)(const std::string& cmd,
const std::string& param);
// for subscribers only
// when any publishers push an event,
// the 'CorbaComm' will invoke subscriber's callback
//
typedef void (*EventCallback_t)(const std::string& topic,
const std::string& param);
// for event publisher, no need to connect a new type (both share the same cmds)
//
typedef std::vector<std::string> Commands;
// for onEvent() and detachEvent() methods
// an SID (Subscription ID, is an ID returned by onEvent()
// if the host would like to unscribe an event,
// calls detachEvent() with this ID
//
// if the hosts call onEvent with the
// same 'event' and 'callback' more than once
// an empty SID return
//
typedef std::string SID;
class CorbaCommImpl;
class CorbaComm {
public:
virtual ~CorbaComm();
static CorbaComm*
connect(const char* hostId, // the host id, such as 'main', 'gui', 'usb'
// can't be nullptr or empty string
Commands offerCommands, // commands the host offers, can be empty
Commands wantCommands, // commands the host wants, can be empty
int argc, char* argv[]);// additional argc/argv
// to init exchange server
// for subscriber, subscriber's 'onEvent()' will be invoked
// when an event arrives
//
virtual SID onEvent(const char* topic, EventCallback_t callback);
virtual void detachEvent(const SID&);
// for publisher to push an event 'topic'
//
virtual bool pushEvent(const char* topic, const char* param);
// for hosts which request data from the other host, or
// for hosts which ask the host do do some action
//
virtual std::string execCmd(const char* cmd, const char* param);
// for hosts which offer the command 'cmd'
// when a client request a command by 'execCmd()'
// command provider's 'onCmd()' will be called
//
virtual void onCmd(const char* cmd, CommandCallback_t cmdCallback);
// Big-5 rule
//
CorbaComm(const CorbaComm&) = delete;
CorbaComm(CorbaComm&&) = delete;
CorbaComm& operator=(const CorbaComm&) = delete;
CorbaComm& operator=(CorbaComm&&) = delete;
protected:
CorbaComm() = default;
private:
CorbaComm(const char* hostId,
Commands offerCommands,
Commands wantCommands,
int argc,
char* argv[]);
static CorbaComm* _ccserver;
static CorbaCommImpl* _impl;
};
}; // namespace cc
#endif