634819ed85d98f9a9ed6744248237d0fcde29cb3
[platform/core/context/context-service.git] / src / ProviderHandler.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_PROVIDER_HANDLER_H_
18 #define _CONTEXT_PROVIDER_HANDLER_H_
19
20 #include <string>
21 #include <list>
22 #include <map>
23 #include <ContextProvider.h>
24 #include "ProviderLoader.h"
25
26 namespace ctx {
27
28         class Credentials;
29         class RequestInfo;
30
31         class ProviderHandler {
32                 typedef std::list<RequestInfo*> RequestList;
33                 typedef std::map<std::string, ProviderHandler*> InstanceMap;
34
35         public:
36                 bool isSupported();
37                 bool isAllowed(const Credentials *creds);
38
39                 void subscribe(RequestInfo *request);
40                 void unsubscribe(RequestInfo *request);
41                 void read(RequestInfo *request);
42                 void write(RequestInfo *request);
43
44                 bool publish(ctx::Json &option, int error, ctx::Json &dataUpdated);
45                 bool replyToRead(ctx::Json &option, int error, ctx::Json &dataRead);
46
47                 static ProviderHandler* getInstance(const char *subject, bool force);
48                 static void purge();
49
50         private:
51                 const char *__subject;
52                 ContextProvider *__provider;
53                 RequestList __subscribeRequests;
54                 RequestList __readRequests;
55                 ProviderLoader __loader;
56
57                 static InstanceMap __instanceMap;
58
59                 ProviderHandler(const char *subject);
60                 ~ProviderHandler();
61
62                 bool __loadProvider();
63                 RequestList::iterator __findRequest(RequestList &reqList, Json &option);
64                 RequestList::iterator __findRequest(RequestList &reqList, std::string client, int reqId);
65                 RequestList::iterator __findRequest(RequestList::iterator begin, RequestList::iterator end, Json &option);
66
67         };      /* class ProviderHandler */
68
69 }       /* namespace ctx */
70
71 #endif  /* _CONTEXT_PROVIDER_HANDLER_H_ */