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