Migrate from 2.4 code repo
[platform/core/context/context-service.git] / src / context_mgr_impl.h
1 /*
2  * Copyright (c) 2014 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_iface.h>
24 #include "request.h"
25
26 #define TRIGGER_CLIENT_NAME "TRIGGER"
27
28 namespace ctx {
29
30         class context_manager_impl : public context_manager_iface {
31                 public:
32                         typedef std::list<request_info*> request_list_t;
33
34                         context_manager_impl();
35                         ~context_manager_impl();
36
37                         bool init();
38                         void release();
39
40                         void assign_request(ctx::request_info* request);
41                         bool is_supported(const char* subject, const char* zone);
42
43                         // From the interface class
44                         bool register_provider(const char* subject, ctx::context_provider_iface* cp);
45                         bool publish(const char* subject, ctx::json& option, int error, ctx::json& data_updated, const char* zone);
46                         bool reply_to_read(const char* subject, ctx::json& option, int error, ctx::json& data_read, const char* zone);
47                         // ---
48
49                 private:
50                         typedef std::vector<context_provider_iface*> provider_list_t;
51                         typedef std::map<std::string, context_provider_iface*> subject_provider_map_t;
52
53                         provider_list_t provider_list;
54                         request_list_t subscribe_request_list;
55                         request_list_t read_request_list;
56                         subject_provider_map_t subject_provider_map;
57
58                         void load_provider(ctx::context_provider_iface* provider);
59
60                         void subscribe(request_info* request, context_provider_iface* provider);
61                         void unsubscribe(request_info* request);
62                         void read(request_info* request, context_provider_iface* provider);
63                         void write(request_info* request, context_provider_iface* provider);
64
65                         bool check_permission(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, const char* zone);
69                         bool _reply_to_read(const char* subject, ctx::json option, int error, ctx::json data_read, const char* zone);
70
71                         request_list_t::iterator find_request(request_list_t& r_list, std::string subject, json& option, const char* zone);
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, const char* zone);
74
75         };      /* class context_manager_impl */
76
77 }       /* namespace ctx */
78
79 #endif  /* End of __CONTEXT_MANAGER_IMPL_H__ */