Apply Tizen C++ coding style to Context Trigger
[platform/core/context/context-service.git] / src / trigger / ContextMonitor.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_
18 #define _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_
19
20 #include <list>
21 #include <map>
22 #include <Json.h>
23
24 namespace ctx {
25
26         class context_manager_impl;
27
28 namespace trigger {
29
30         class IContextListener;
31         class FactRequest;
32
33         class ContextMonitor {
34         public:
35                 static ContextMonitor* getInstance();
36                 static void setContextManager(context_manager_impl* ctx_mgr);
37                 static void destroy();
38
39                 int subscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
40                 int unsubscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
41                 int read(std::string subject, Json option, IContextListener* listener);
42                 bool isSupported(std::string subject);
43                 bool isAllowed(const char *client, const char *subject);
44
45                 void replyResult(int reqId, int error, Json *requestResult = NULL);
46                 void replyResult(int reqId, int error, const char *subject, Json *option, Json *fact);
47                 void publishFact(int reqId, int error, const char *subject, Json *option, Json *fact);
48
49         private:
50                 ContextMonitor();
51                 ContextMonitor(const ContextMonitor& other);
52                 ~ContextMonitor();
53
54                 static ContextMonitor *__instance;
55                 static context_manager_impl *__contextMgr;
56
57                 int __subscribe(const char* subject, Json* option, IContextListener* listener);
58                 void __unsubscribe(const char *subject, int subscriptionId);
59                 int __read(const char *subject, Json *option, IContextListener* listener);
60
61                 struct SubscrInfo {
62                         int sid;
63                         std::string subject;
64                         Json option;
65                         std::list<IContextListener*> listenerList;
66
67                         SubscrInfo(int id, const char *subj, Json *opt) :
68                                 sid(id),
69                                 subject(subj)
70                         {
71                                 if (opt)
72                                         option = *opt;
73                         }
74                 };
75
76                 std::map<int, SubscrInfo*> __subscrMap;
77                 std::map<int, SubscrInfo*> ___readMap;
78
79                 int __findSub(request_type type, const char *subject, Json *option);
80                 bool __addSub(request_type type, int sid, const char *subject, Json *option, IContextListener* listener);
81                 void __removeSub(request_type type, const char *subject, Json *option);
82                 void __removeSub(request_type type, int sid);
83                 int __addListener(request_type type, int sid, IContextListener* listener);
84                 int __removeListener(request_type type, int sid, IContextListener* listener);
85
86         };      /* class ContextMonitor */
87
88 }       /* namespace trigger */
89 }       /* namespace ctx */
90
91 #endif  /* End of _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_ */