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_PROVIDER_HANDLER_H_
18 #define _CONTEXT_PROVIDER_HANDLER_H_
23 #include <ContextProvider.h>
24 #include "ProviderLoader.h"
31 class ProviderHandler {
32 typedef std::list<RequestInfo*> RequestList;
33 typedef std::map<std::string, ProviderHandler*> InstanceMap;
37 bool isAllowed(const Credentials *creds);
39 void subscribe(RequestInfo *request);
40 void unsubscribe(RequestInfo *request);
41 void read(RequestInfo *request);
42 void write(RequestInfo *request);
44 bool publish(ctx::Json &option, int error, ctx::Json &dataUpdated);
45 bool replyToRead(ctx::Json &option, int error, ctx::Json &dataRead);
47 static ProviderHandler* getInstance(std::string subject, bool force);
49 static int unregisterCustomProvider(std::string subject);
52 std::string __subject;
53 ContextProvider *__provider;
54 RequestList __subscribeRequests;
55 RequestList __readRequests;
56 ProviderLoader __loader;
57 bool __deleteScheduled;
59 static InstanceMap __instanceMap;
61 ProviderHandler(const std::string &subject);
64 bool __loadProvider();
66 void __scheduleToDelete();
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);
72 static gboolean __deletor(gpointer data);
74 }; /* class ProviderHandler */
78 #endif /* _CONTEXT_PROVIDER_HANDLER_H_ */