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_
23 #include <DBusTypes.h>
31 class IContextListener;
34 class ContextMonitor {
36 static ContextMonitor* getInstance();
37 static void setContextManager(ContextManager* ctxMgr);
38 static void destroy();
40 int subscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
41 int unsubscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
42 int read(std::string subject, Json option, IContextListener* listener);
43 bool isSupported(std::string subject);
44 bool isAllowed(const char *client, const char *subject);
46 void replyResult(int reqId, int error, Json *requestResult = NULL);
47 void replyResult(int reqId, int error, const char *subject, Json *option, Json *fact);
48 void publishFact(int reqId, int error, const char *subject, Json *option, Json *fact);
52 ContextMonitor(const ContextMonitor& other);
55 static ContextMonitor *__instance;
56 static ContextManager *__contextMgr;
58 int __subscribe(const char* subject, Json* option, IContextListener* listener);
59 void __unsubscribe(const char *subject, int subscriptionId);
60 int __read(const char *subject, Json *option, IContextListener* listener);
66 std::list<IContextListener*> listenerList;
68 SubscrInfo(int id, const char *subj, Json *opt) :
77 std::map<int, SubscrInfo*> __subscrMap;
78 std::map<int, SubscrInfo*> __readMap;
80 int __findSub(RequestType type, const char *subject, Json *option);
81 bool __addSub(RequestType type, int sid, const char *subject, Json *option, IContextListener* listener);
82 void __removeSub(RequestType type, const char *subject, Json *option);
83 void __removeSub(RequestType type, int sid);
84 int __addListener(RequestType type, int sid, IContextListener* listener);
85 int __removeListener(RequestType type, int sid, IContextListener* listener);
87 }; /* class ContextMonitor */
89 } /* namespace trigger */
92 #endif /* End of _CONTEXT_TRIGGER_CONTEXT_MONITOR_H_ */