Add new event type for uninstall/upgrade packages.
[platform/framework/web/data-provider-master.git] / include / instance.h
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /*!
18  * \note
19  * An instance has three states.
20  * ACTIVATED, DEACTIVATED, DESTROYED
21  *
22  * When the master is launched and someone requiers to create this instance,
23  * The master just allocate a heap for new instance.
24  * We defined this as "DEACTIVATED" state.
25  *
26  * After master successfully allocate heap for an instance,
27  * It will send a load request to a specified slave
28  * (The slave will be specified when a package informaion is
29  * prepared via configuration file of each livebox packages.)
30  * We defined this as "REQUEST_TO_ACTIVATE" state.
31  *
32  * After the slave create a new instance, it will sends back
33  * "created" event to the master.
34  * Then the master will change the state of the instance to
35  * "ACTIVATED".
36  *
37  * Sometimes, slaves can meet some unexpected problems then
38  * it will tries to clear all problems and tries to keep them in safe env.
39  * To do this, master or slave can be terminated.
40  * In this case, the master has to find the fault module(crashed livebox)
41  * and prevent it from loading at the slave.
42  * And it will send requests for re-creating all other normal liveboxes.
43  * We defined this as "REQUEST_TO_REACTIVATE".
44  *
45  * After slave is launched again(recovered from fault situation), it will
46  * receives "re-create" event from the master, then it will create all
47  * instances of requested liveboxes.
48  *
49  * When the master receives "created" event from the slaves,
50  * It will change the instance's state to "ACTIVATED"
51  * But now, the master will not send "created" event to the clients.
52  *
53  * Because the clients don't want to know the re-created liveboxes.
54  * They just want to know about fault liveboxes to display deactivated
55  * message.
56  *
57  * Sometimes the master can send requests to the slave to unload instances.
58  * We defined this as "REQUEST_TO_DEACTIVATE".
59  *
60  * After the slave successfully destroy instances,
61  * The master will change the instance's state to "DEACTIVATED"
62  * It is same state with the first time when it is created in the master.
63  *
64  * Sometimes, the instances can be deleted permanently from the master and slave.
65  * We called this "destorying an instance".
66  * So we defined its states as "DESTROYED".
67  * It can make confusing us, the "DESTROYED" means like the instance is already deleted from the
68  * heap,. 
69  * Yes, it is right. But the instance cannot be deleted directly.
70  * Because some callbacks still reference it to complete its job.
71  * So the instance needs to keep this DESTROYED state for a while
72  * until all callbacks are done for their remained jobs.
73  *
74  * To unload the instance from the slave,
75  * The master should send a request to the slave,
76  * And the master should keep the instance until it receives "deleted" event from the slave.
77  * We defined this state as "REQUEST_TO_DESTROY".
78  * 
79  * After master receives "deleted" event from the slave,
80  * It will change the state of an master to "DESTROYED"
81  *
82  * There is one more event to change the state of an instance to "DESTROYED".
83  * In case of system created livebox, it could be destroyed itself.
84  * So the slave will send "deleted" event to the master directly.
85  * Even if the master doesn't requests to delete it.
86  *
87  * In this case, the master will change the state of an instance to
88  * "DESTROYED" state. but it will wait to delete it from the heap until
89  * reference count of an instance reaches to ZERO.
90  */
91
92 enum instance_event {
93         INSTANCE_EVENT_DESTROY,
94         INSTNACE_EVENT_UNKNOWN
95 };
96
97 enum instance_destroy_type {
98         INSTANCE_DESTROY_DEFAULT = 0x00,
99         INSTANCE_DESTROY_UPGRADE = 0x01,
100         INSTANCE_DESTROY_UNINSTALL = 0x02,
101         INSTANCE_DESTROY_TERMINATE = 0x03,
102         INSTANCE_DESTROY_FAULT = 0x04,
103         INSTANCE_DESTROY_UNKNOWN = 0x05,
104 };
105
106 enum instance_state {
107         INST_INIT = 0x0, /*!< Only keeps in the master */
108
109         /*!
110          */
111         INST_ACTIVATED, /*!< This instance is loaded to the slave */
112         INST_REQUEST_TO_ACTIVATE, /*!< Sent a request to a slave to load this */
113         INST_REQUEST_TO_REACTIVATE, /*!< Sent a request to a slave to load this without "created" event for clients(viewer) */
114
115         /*!
116          */
117         INST_DESTROYED, /*!< Instance is unloaded and also it requires to be deleted from the master */
118         INST_REQUEST_TO_DESTROY /*!< Sent a request to a slave, when the master receives deleted event, the master will delete this */
119 };
120
121 enum livebox_visible_state { /*!< Must be sync'd with livebox-viewer */
122         LB_SHOW = 0x00, /*!< Livebox is showed. Default state */
123         LB_HIDE = 0x01, /*!< Livebox is hide, with no update event, but keep update timer */
124
125         LB_HIDE_WITH_PAUSE = 0x02, /*!< Livebix is hide, it needs to be paused (with freezed update timer) */
126
127         LB_VISIBLE_ERROR = 0xFFFFFFFF /* To enlarge the size of this enumeration type */
128 };
129
130 #define IS_PD   1
131 #define IS_LB   0
132
133 struct inst_info;
134 struct pkg_info;
135 struct script_handle;
136 struct client_node;
137
138 extern struct inst_info *instance_create(struct client_node *client, double timestamp, const char *pkgname, const char *content, const char *cluster, const char *category, double period, int width, int height);
139 extern int instance_destroy(struct inst_info *inst, enum instance_destroy_type type);
140 extern int instance_reload(struct inst_info *inst, enum instance_destroy_type type);
141
142 extern struct inst_info * instance_ref(struct inst_info *inst);
143 extern struct inst_info * instance_unref(struct inst_info *inst);
144
145 extern int instance_state_reset(struct inst_info *inst);
146 extern int instance_destroyed(struct inst_info *inst);
147
148 extern int instance_reactivate(struct inst_info *inst);
149 extern int instance_activate(struct inst_info *inst);
150
151 extern int instance_recover_state(struct inst_info *inst);
152 extern int instance_need_slave(struct inst_info *inst);
153
154 extern void instance_set_lb_info(struct inst_info *inst, double priority, const char *content, const char *title);
155 extern void instance_set_lb_size(struct inst_info *inst, int w, int h);
156 extern void instance_set_pd_size(struct inst_info *inst, int w, int h);
157
158 extern int instance_set_pinup(struct inst_info *inst, int pinup);
159 extern int instance_resize(struct inst_info *inst, int w, int h);
160 extern int instance_hold_scroll(struct inst_info *inst, int seize);
161 extern int instance_set_period(struct inst_info *inst, double period);
162 extern int instance_clicked(struct inst_info *inst, const char *event, double timestamp, double x, double y);
163 extern int instance_text_signal_emit(struct inst_info *inst, const char *emission, const char *source, double sx, double sy, double ex, double ey);
164 extern int instance_signal_emit(struct inst_info *inst, const char *emission, const char *source, double sx, double sy, double ex, double ey, double x, double y, int down);
165 extern int instance_change_group(struct inst_info *inst, const char *cluster, const char *category);
166 extern int instance_set_visible_state(struct inst_info *inst, enum livebox_visible_state state);
167 extern enum livebox_visible_state instance_visible_state(struct inst_info *inst);
168 extern int instance_set_update_mode(struct inst_info *inst, int active_update);
169 extern int instance_active_update(struct inst_info *inst);
170
171 /*!
172  * \note
173  * getter
174  */
175 extern const double const instance_timestamp(const struct inst_info *inst);
176 extern struct pkg_info * const instance_package(const struct inst_info *inst);
177 extern struct script_info * const instance_lb_script(const struct inst_info *inst);
178 extern struct script_info * const instance_pd_script(const struct inst_info *inst);
179 extern struct buffer_info * const instance_pd_buffer(const struct inst_info *inst);
180 extern struct buffer_info * const instance_lb_buffer(const struct inst_info *inst);
181 extern const char * const instance_id(const struct inst_info *inst);
182 extern const char * const instance_content(const struct inst_info *inst);
183 extern const char * const instance_category(const struct inst_info *inst);
184 extern const char * const instance_cluster(const struct inst_info *inst);
185 extern const char * const instance_title(const struct inst_info *inst);
186 extern const char * const instance_auto_launch(const struct inst_info *inst);
187 extern const int const instance_priority(const struct inst_info *inst);
188 extern const struct client_node * const instance_client(const struct inst_info *inst);
189 extern const double const instance_period(const struct inst_info *inst);
190 extern const int const instance_timeout(const struct inst_info *inst);
191 extern const int const instance_lb_width(const struct inst_info *inst);
192 extern const int const instance_lb_height(const struct inst_info *inst);
193 extern const int const instance_pd_width(const struct inst_info *inst);
194 extern const int const instance_pd_height(const struct inst_info *inst);
195 extern const enum instance_state const instance_state(const struct inst_info *inst);
196
197 /*!
198  * event
199  */
200 extern int instance_unicast_created_event(struct inst_info *inst, struct client_node *client);
201 extern int instance_unicast_deleted_event(struct inst_info *inst, struct client_node *client);
202
203 extern int instance_create_lb_buffer(struct inst_info *inst);
204 extern int instance_create_pd_buffer(struct inst_info *inst);
205
206 extern void instance_slave_set_pd_pos(struct inst_info *inst, double x, double y);
207 extern void instance_slave_get_pd_pos(struct inst_info *inst, double *x, double *y);
208
209 extern int instance_slave_open_pd(struct inst_info *inst, struct client_node *client);
210 extern int instance_slave_close_pd(struct inst_info *inst, struct client_node *client);
211
212 extern int instance_freeze_updator(struct inst_info *inst);
213 extern int instance_thaw_updator(struct inst_info *inst);
214
215 extern int instance_send_access_event(struct inst_info *inst, int status);
216
217 extern int instance_lb_update_begin(struct inst_info *inst, double priority, const char *content, const char *title);
218 extern int instance_lb_update_end(struct inst_info *inst);
219
220 extern int instance_pd_update_begin(struct inst_info *inst);
221 extern int instance_pd_update_end(struct inst_info *inst);
222
223 extern void instance_pd_updated(const char *pkgname, const char *id, const char *descfile);
224 extern void instance_lb_updated_by_instance(struct inst_info *inst, const char *safe_file);
225 extern void instance_pd_updated_by_instance(struct inst_info *inst, const char *descfile);
226
227 extern int instance_client_pd_destroyed(struct inst_info *inst, int status);
228 extern int instance_client_pd_created(struct inst_info *inst, int status);
229
230 extern int instance_send_access_status(struct inst_info *inst, int status);
231 extern int instance_forward_packet(struct inst_info *inst, struct packet *packet);
232
233 extern struct client_node *instance_pd_owner(struct inst_info *inst);
234
235 /*!
236  * Multiple viewer
237  */
238 extern int instance_add_client(struct inst_info *inst, struct client_node *client);
239 extern int instance_del_client(struct inst_info *inst, struct client_node *client);
240 extern int instance_has_client(struct inst_info *inst, struct client_node *client);
241 extern void *instance_client_list(struct inst_info *inst);
242
243 extern int instance_init(void);
244 extern int instance_fini(void);
245
246 extern int instance_event_callback_add(struct inst_info *inst, enum instance_event type, int (*event_cb)(struct inst_info *inst, void *data), void *data);
247 extern int instance_event_callback_del(struct inst_info *inst, enum instance_event type, int (*event_cb)(struct inst_info *inst, void *data));
248
249 /*!
250  */
251 extern int instance_set_data(struct inst_info *inst, const char *tag, void *data);
252 extern void *instance_del_data(struct inst_info *inst, const char *tag);
253 extern void *instance_get_data(struct inst_info *inst, const char *tag);
254
255 /* End of a file */