Migrate from 2.4 code repo
[platform/core/context/context-service.git] / src / context_trigger / trigger.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_CONTEXT_TRIGGER_H__
18 #define __CONTEXT_CONTEXT_TRIGGER_H__
19
20 #include <event_driven.h>
21 #include "../request.h"
22 #include "fact.h"
23
24 namespace ctx {
25
26         class fact_reader;
27         class rule_manager;
28         class client_request;
29         class context_manager_impl;
30         class context_trigger : public event_driven_thread {
31                 public:
32                         context_trigger();
33                         ~context_trigger();
34
35                         bool init(ctx::context_manager_impl* mgr);
36                         void release();
37
38                         bool assign_request(ctx::request_info* request);
39                         void push_fact(int req_id, int error, const char* subject, ctx::json& option, ctx::json& data, const char* zone);
40                         bool publish(int rule_id, int error, ctx::json data);
41                         bool _publish(int rule_id, int error, ctx::json data);
42
43
44                 private:
45                         enum event_type_e {
46                                 ETYPE_REQUEST = 1,      // A request received from a client
47                                 ETYPE_FACT,                     // A context fact received from a CA
48                                 ETYPE_INITIALIZE,       // Initialization
49                         };
50
51                         ctx::fact_reader *_reader;
52
53                         void on_thread_event_popped(int type, void* data);
54                         void delete_thread_event(int type, void* data);
55
56                         void process_request(ctx::request_info* request);
57                         void process_fact(ctx::context_fact* fact);
58                         void process_initialize(void);
59
60                         void add_rule(ctx::request_info* request);
61                         void remove_rule(ctx::request_info* request);
62                         void enable_rule(ctx::request_info* request);
63                         void disable_rule(ctx::request_info* request);
64                         void get_rule_by_id(ctx::request_info* request);
65                         void get_rule_ids(ctx::request_info* request);
66
67                         ctx::rule_manager* rule_mgr;
68         };
69
70 }       /* namespace ctx */
71
72 #endif  /* End of __CONTEXT_CONTEXT_TRIGGER_H__ */