2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_
18 #define _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_
26 class context_manager_impl;
30 class IContextListener;
33 class ContextMonitor {
35 static ContextMonitor* getInstance();
36 static void setContextManager(context_manager_impl* ctx_mgr);
37 static void destroy();
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);
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);
51 ContextMonitor(const ContextMonitor& other);
54 static ContextMonitor *__instance;
55 static context_manager_impl *__contextMgr;
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);
65 std::list<IContextListener*> listenerList;
67 SubscrInfo(int id, const char *subj, Json *opt) :
76 std::map<int, SubscrInfo*> __subscrMap;
77 std::map<int, SubscrInfo*> ___readMap;
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);
86 }; /* class ContextMonitor */
88 } /* namespace trigger */
91 #endif /* End of _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_ */