Remove profile build dependencies
[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(std::string subject, bool force);
48                 static void purge();
49                 static int unregisterCustomProvider(std::string subject);
50
51         private:
52                 std::string __subject;
53                 ContextProvider *__provider;
54                 RequestList __subscribeRequests;
55                 RequestList __readRequests;
56                 ProviderLoader __loader;
57                 bool __deleteScheduled;
58
59                 static InstanceMap __instanceMap;
60
61                 ProviderHandler(const std::string &subject);
62                 ~ProviderHandler();
63
64                 bool __loadProvider();
65                 bool __idle();
66                 void __scheduleToDelete();
67
68                 RequestList::iterator __findRequest(RequestList &reqList, Json &option);
69                 RequestList::iterator __findRequest(RequestList &reqList, std::string client, int reqId);
70                 RequestList::iterator __findRequest(RequestList::iterator begin, RequestList::iterator end, Json &option);
71
72                 static gboolean __deletor(gpointer data);
73
74         };      /* class ProviderHandler */
75
76 }       /* namespace ctx */
77
78 #endif  /* _CONTEXT_PROVIDER_HANDLER_H_ */