2 * Copyright (c) 2014 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_FACT_READER_H__
18 #define __CONTEXT_FACT_READER_H__
22 #include "../context_mgr_impl.h"
27 class context_trigger;
31 fact_reader(context_manager_impl* mgr, context_trigger* trigger);
34 bool is_supported(const char* subject, const char* zone);
36 int subscribe(const char* subject, json* option, const char* zone, bool wait_response = false);
37 void unsubscribe(const char* subject, json* option, const char* zone);
38 void unsubscribe(int subscription_id);
39 bool read(const char* subject, json* option, const char* zone, context_fact& fact);
41 void reply_result(int req_id, int error, const char* zone, json* request_result = NULL, json* fact = NULL);
42 void publish_fact(int req_id, int error, const char* zone, const char* subject, json* option, json* fact);
45 static context_manager_impl* _context_mgr;
46 static context_trigger* _trigger;
48 struct subscr_info_s {
52 std::string zone_name;
53 subscr_info_s(int id, const char* subj, ctx::json* opt, const char* zone)
54 : sid(id), subject(subj)
64 typedef std::list<subscr_info_s*> subscr_list_t;
65 subscr_list_t subscr_list;
67 int find_sub(const char* subject, json* option, const char* zone);
68 bool add_sub(int sid, const char* subject, json* option, const char* zone);
69 void remove_sub(const char* subject, json* option, const char* zone);
70 void remove_sub(int sid);
72 static gboolean send_request(gpointer data);
77 #endif /* End of __CONTEXT_FACT_READER_H__ */