tizen 2.4 release
[framework/context/context-service.git] / src / context_mgr_impl.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_MANAGER_IMPL_H__
18 #define __CONTEXT_MANAGER_IMPL_H__
19
20 #include <vector>
21 #include <list>
22 #include <map>
23 #include <context_mgr.h>
24 #include <context_mgr_iface.h>
25 #include "request.h"
26
27 #define TRIGGER_CLIENT_NAME "TRIGGER"
28
29 namespace ctx {
30
31         class context_manager_impl : public context_manager_iface {
32         public:
33                 typedef std::list<request_info*> request_list_t;
34
35                 context_manager_impl();
36                 ~context_manager_impl();
37
38                 bool init();
39                 void release();
40
41                 void assign_request(ctx::request_info *request);
42                 bool is_supported(const char *subject);
43                 bool is_allowed(const char *client, const char *subject);
44                 bool pop_trigger_item(std::string &subject, int &operation, ctx::json &attributes, ctx::json &options);
45
46                 /* From the interface class */
47                 bool register_provider(const char *subject, context_provider_info &provider_info);
48                 bool register_trigger_item(const char *subject, int operation, ctx::json attributes, ctx::json options);
49                 bool publish(const char *subject, ctx::json &option, int error, ctx::json &data_updated);
50                 bool reply_to_read(const char *subject, ctx::json &option, int error, ctx::json &data_read);
51
52         private:
53                 typedef std::map<std::string, context_provider_info> provider_map_t;
54
55                 request_list_t subscribe_request_list;
56                 request_list_t read_request_list;
57                 provider_map_t provider_map;
58
59                 void subscribe(request_info *request);
60                 void unsubscribe(request_info *request);
61                 void read(request_info *request);
62                 void write(request_info *request);
63                 void is_supported(request_info *request);
64
65                 context_provider_iface *get_provider(request_info *request);
66
67                 static gboolean thread_switcher(gpointer data);
68                 bool _publish(const char *subject, ctx::json option, int error, ctx::json data_updated);
69                 bool _reply_to_read(const char *subject, ctx::json option, int error, ctx::json data_read);
70
71                 request_list_t::iterator find_request(request_list_t& r_list, std::string subject, json& option);
72                 request_list_t::iterator find_request(request_list_t& r_list, std::string client, int req_id);
73                 request_list_t::iterator find_request(request_list_t::iterator begin, request_list_t::iterator end, std::string subject, json& option);
74
75         };      /* class context_manager_impl */
76
77 }       /* namespace ctx */
78
79 #endif  /* End of __CONTEXT_MANAGER_IMPL_H__ */