-
Notifications
You must be signed in to change notification settings - Fork 1
/
corbaComm_impl.h
126 lines (110 loc) · 4.25 KB
/
corbaComm_impl.h
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
#ifndef _CORBA_COMM_IMPL_H
#define _CORBA_COMM_IMPL_H
#include <map>
#include <utility>
#include <vector>
#include <array>
#include <mutex>
#include <condition_variable>
#include <string.h>
#include "corbaComm.hh"
#include "corbaComm.h"
#include "cos.h"
#include "notify_impl.h"
#include "provider.h"
namespace cc {
class CorbaCommImpl {
public:
typedef std::pair<std::string, std::string> Cmd2ProviderInfo;
struct SupplierFailureException { };
struct ConsumerFailureException { };
struct CorbaObjectImplFailure { };
~CorbaCommImpl();
void tryDispatchEvent(const CosN::StructuredEvent&) const;
void trySetProviderInfo(const CosN::StructuredEvent&);
void trySetProviderInfo(const Cmd2ProviderInfo&);
void tryPublishOfferService(const CosN::StructuredEvent&) const;
// Big-5 rules
CorbaCommImpl() = delete;
CorbaCommImpl(const CorbaCommImpl&) = delete;
CorbaCommImpl(CorbaCommImpl&&) = delete;
CorbaCommImpl& operator=(const CorbaCommImpl&) = delete;
CorbaCommImpl& operator=(CorbaCommImpl&&) = delete;
private:
friend class CorbaComm;
typedef std::pair<std::string, std::string> Filter;
typedef std::array<Filter,2> Filters;
// CorbaCommImpl
//
CorbaCommImpl(const char* hostId,
Commands offerCommands,
Commands wantCommands,
int argc, char* argv[]);
SID onEvent(const char* topic, EventCallback_t callback);
void detachEvent(const SID&);
bool pushEvent(const char* topic, const char* param) const;
bool pushEvent(const char* topic, const char* param,
const Filters& filters) const;
std::string execCmd(const char* cmd, const char* param);
void onCmd(const char* cmd, CommandCallback_t cmdCallback);
SID genSID() const;
void unblockedCmd(const std::string&);
void clearObjReference(const std::string&);
// CORBA
//
void newProviderCorbaObject();
bool initPushConsumer();
bool initPushSupplier();
bool initProviderImpl(const CosNaming::Name&);
bool bindObjectToName(const CosNaming::Name&, CORBA::Object_ptr);
CosNCA::EventChannel_ptr getOrCreateChannel();
CORBA::Object_ptr resolveObjectReference(const CosNaming::Name&) const;
// CorbaCommImpl
//
void publishCommandsType(const Commands&, std::string) const;
void publishOfferCommands(const Commands&) const;
void publishWantCommands(const Commands&) const;
typedef std::vector<EventCallback_t> AllCallbacks;
typedef std::map<std::string, AllCallbacks> SubscribeMap;
typedef std::pair<std::string, EventCallback_t> EvtInfo;
typedef std::map<std::string, EvtInfo> EvtInfoMap;
typedef std::map<std::string, CommandCallback_t> ProviderMap;
// for host which wants to understand who is request provider
//
typedef std::map<std::string, std::string> ProviderInfoMap;
typedef std::map<std::string, CorbaCommModule::Provider_ptr> ObjRefMap;
std::string _hostId;
Commands _offerCommands;
Commands _wantCommands;
SubscribeMap _subscribeMap;
EvtInfoMap _evtInfoMap;
ProviderMap _providerMap;
ProviderInfoMap _providerInfoMap;
ObjRefMap _objRefMap;
// CORBA
//
PushSupplier_i* _pushSupplier;
PushConsumer_i* _pushConsumer;
CORBA::ORB_var _orb;
PortableServer::POA_var _poa;
CosNaming::NamingContext_var _nameCtx;
PortableServer::Servant_var<ProviderImpl> _providerImpl;
bool _orbRunning;
// for 'lazy command routing' sync
//
struct SyncObj {
std::unique_ptr<std::mutex> _mutex;
std::unique_ptr<std::condition_variable> _cv;
bool _cmdReady;
SyncObj() {
_mutex = std::make_unique<std::mutex>();
_cv = std::make_unique<std::condition_variable>();
_cmdReady = false;
}
};
std::map<std::string, SyncObj> _syncMap;
const std::string _channelName = "EventChannel";
const std::string _factoryName = "ChannelFactory";
};
}; // namespace cc
#endif