tizen 2.3 release
[apps/livebox/data-provider-master.git] / include / slave_life.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  * Managing the reference counter of a slave
19  */
20
21 struct slave_node;
22
23 enum slave_event {
24         SLAVE_EVENT_ACTIVATE,
25         SLAVE_EVENT_DEACTIVATE, /* deactivate callback, can return REACTIVATE, DEFAULT */
26         SLAVE_EVENT_DELETE, /* Callbacks for this event type, must has not to do something with slave object.
27                                use this only for just notice the state of slave */
28         SLAVE_EVENT_FAULT, /* Critical fault */
29
30         SLAVE_EVENT_PAUSE,
31         SLAVE_EVENT_RESUME,
32
33         SLAVE_NEED_TO_REACTIVATE
34 };
35
36 enum slave_state {
37         /*!
38          * Launch the slave but not yet receives "hello" packet
39          */
40         SLAVE_REQUEST_TO_LAUNCH,
41
42         /*!
43          * \note
44          * Terminate the slave but not yet receives dead signal
45          */
46         SLAVE_REQUEST_TO_TERMINATE,
47
48         /*!
49          * \note
50          * No slave process exists, just slave object created
51          */
52         SLAVE_TERMINATED,
53
54         /*!
55          * \note
56          * State change request is sent,
57          */
58         SLAVE_REQUEST_TO_PAUSE,
59         SLAVE_REQUEST_TO_RESUME,
60
61         /*!
62          * \note
63          * Request an action for disconnecting to master from the provider side.
64          * This flag should be treated as an activated state.
65          */
66         SLAVE_REQUEST_TO_DISCONNECT,
67
68         /*!
69          * \note
70          * SLAVE_ACTIVATED = { SLAVE_PAUSED, SLAVE_RESUMED }
71          */
72         SLAVE_PAUSED,
73         SLAVE_RESUMED,
74
75         SLAVE_ERROR = 0xFF /* Explicitly define the size of this enum type */
76 };
77
78 enum PROVIDER_CTRL {
79         PROVIDER_CTRL_DEFAULT = 0x00,                   /*!< Set default control operation */
80         PROVIDER_CTRL_MANUAL_TERMINATION = 0x01,        /*!< Terminate process manually */
81         PROVIDER_CTRL_MANUAL_REACTIVATION = 0x02,       /*!< Reactivate process manually */
82 };
83
84 extern struct slave_node *slave_ref(struct slave_node *slave);
85 extern struct slave_node *slave_unref(struct slave_node *slave);
86 extern const int const slave_refcnt(struct slave_node *slave);
87
88 /*!
89  * \brief
90  * Create a new slave object or destroy it
91  *
92  * \param[in] name
93  * \param[in] is_secured
94  * \param[in] abi
95  * \param[in] pkgname
96  * \param[in] period
97  * \return slave_node
98  */
99 extern struct slave_node *slave_create(const char *name, int is_secured, const char *abi, const char *pkgname, int network, const char *hw_acceleration);
100
101 /*!
102  * \brief
103  * \param[in] slave
104  * \return void
105  */
106 extern void slave_destroy(struct slave_node *slave);
107
108 /*!
109  * \brief
110  * Launch or terminate a slave
111  * \param[in] slave
112  * \return int
113  */
114 extern int slave_activate(struct slave_node *slave);
115
116 /*!
117  * To check the slave's activation state
118  */
119 extern const int const slave_is_activated(struct slave_node *slave);
120 extern int slave_activated(struct slave_node *slave);
121
122 extern int slave_give_more_ttl(struct slave_node *slave);
123 extern int slave_freeze_ttl(struct slave_node *slave);
124 extern int slave_thaw_ttl(struct slave_node *slave);
125 extern int slave_expired_ttl(struct slave_node *slave);
126
127 /*!
128  * \NOTE
129  * To mangage the unexpected termination of a slave
130  * After this function call, the slave object can be deleted
131  */
132 extern struct slave_node *slave_deactivated_by_fault(struct slave_node *slave) __attribute__((warn_unused_result));
133
134 /*!
135  * \NOTE
136  * After this function, the slave object can be deleted
137  */
138 extern struct slave_node *slave_deactivated(struct slave_node *slave) __attribute__((warn_unused_result));
139
140 extern int slave_event_callback_add(struct slave_node *slave, enum slave_event event, int (*cb)(struct slave_node *, void *), void *data);
141 extern int slave_event_callback_del(struct slave_node *slave, enum slave_event event, int (*cb)(struct slave_node *, void *), void *data);
142
143 extern int slave_set_data(struct slave_node *slave, const char *tag, void *data);
144 extern void *slave_del_data(struct slave_node *slave, const char *tag);
145 extern void *slave_data(struct slave_node *slave, const char *tag);
146
147 extern struct slave_node *slave_find_by_pid(pid_t pid);
148 extern struct slave_node *slave_find_by_name(const char *name);
149 extern struct slave_node *slave_find_by_pkgname(const char *pkgname);
150 extern struct slave_node *slave_find_by_rpc_handle(int handle);
151
152 extern void slave_dead_handler(struct slave_node *slave);
153 extern const int const slave_is_secured(const struct slave_node *slave);
154 extern const char * const slave_name(const struct slave_node *slave);
155 extern const pid_t const slave_pid(const struct slave_node *slave);
156 extern const char * const slave_abi(const struct slave_node *slave);
157 extern int slave_set_pid(struct slave_node *slave, pid_t pid);
158
159 /*!
160  * \note
161  * Used for making decision of destroying a slave or not
162  * Used for balancing load of the slave.
163  */
164 extern void slave_load_package(struct slave_node *slave);
165 extern void slave_unload_package(struct slave_node *slave);
166 extern int const slave_loaded_package(struct slave_node *slave);
167 extern struct slave_node *slave_find_available(const char *slave_pkgname, const char *abi, int secured, int network, const char *hw_acceleration);
168
169 extern double const slave_ttl(const struct slave_node *slave);
170
171 /*!
172  * \note
173  * Used for making decision of activating a slave or not
174  */
175 extern void slave_load_instance(struct slave_node *slave);
176
177 /*!
178  * \NOTE
179  * After this function call, the slave object can be deleted.
180  */
181 extern struct slave_node *slave_unload_instance(struct slave_node *slave) __attribute__((warn_unused_result));
182
183 extern int const slave_loaded_instance(struct slave_node *slave);
184
185 extern int slave_resume(struct slave_node *slave);
186 extern int slave_pause(struct slave_node *slave);
187
188 extern const char *slave_pkgname(const struct slave_node *slave);
189 extern enum slave_state slave_state(const struct slave_node *slave);
190 extern const char *slave_state_string(const struct slave_node *slave);
191
192 extern const void *slave_list(void);
193 extern int const slave_fault_count(const struct slave_node *slave);
194
195 extern int slave_need_to_reactivate_instances(struct slave_node *slave);
196 extern void slave_set_reactivate_instances(struct slave_node *slave, int reactivate);
197
198 extern void slave_set_reactivation(struct slave_node *slave, int flag);
199 extern int slave_need_to_reactivate(struct slave_node *slave);
200
201 extern int slave_network(const struct slave_node *slave);
202 extern void slave_set_network(struct slave_node *slave, int network);
203
204 extern int slave_deactivate_all(int reactivate, int reactivate_instances, int no_timer);
205 extern int slave_activate_all(void);
206
207 extern void slave_set_control_option(struct slave_node *slave, int ctrl);
208 extern int slave_control_option(struct slave_node *slave);
209
210 extern char *slave_package_name(const char *abi, const char *lbid);
211
212 extern int slave_priority(struct slave_node *slave);
213 extern int slave_set_priority(struct slave_node *slave, int priority);
214
215 /* End of a file */