tizen 2.3 release
[apps/livebox/data-provider-master.git] / src / dead_monitor.c
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 #include <stdio.h>
18 #include <unistd.h>
19
20 #include <gio/gio.h>
21 #include <packet.h>
22 #include <com-core.h>
23 #include <dlog.h>
24
25 #include <Eina.h>
26 #include <dynamicbox_service.h> /* destroy_type for instance.h */
27
28 #include "slave_life.h"
29 #include "client_life.h"
30 #include "instance.h"
31 #include "fault_manager.h"
32 #include "util.h"
33 #include "debug.h"
34 #include "liveinfo.h"
35 #include "conf.h"
36
37 static int evt_cb(int handle, void *data)
38 {
39         struct slave_node *slave;
40         struct client_node *client;
41         struct liveinfo *liveinfo;
42
43         slave = slave_find_by_rpc_handle(handle);
44         if (slave) {
45                 if (slave_pid(slave) != (pid_t)-1) {
46                         switch (slave_state(slave)) {
47                         case SLAVE_REQUEST_TO_DISCONNECT:
48                                 DbgPrint("Disconnected from %d\n", slave_pid(slave));
49                         case SLAVE_REQUEST_TO_TERMINATE:
50                                 slave = slave_deactivated(slave);
51                                 break;
52                         default:
53                                 slave = slave_deactivated_by_fault(slave);
54                                 break;
55                         }
56                 }
57
58                 if (!slave) {
59                         DbgPrint("Slave is deleted\n");
60                 }
61
62                 return 0;
63         }
64
65         client = client_find_by_rpc_handle(handle);
66         if (client) {
67                 if (client_pid(client) != (pid_t)-1) {
68                         client = client_deactivated_by_fault(client);
69                 }
70
71                 if (!client) {
72                         DbgPrint("Client is deleted\n");
73                 }
74
75                 return 0;
76         }
77
78         liveinfo = liveinfo_find_by_handle(handle);
79         if (liveinfo) {
80                 liveinfo_destroy(liveinfo);
81                 return 0;
82         }
83
84         return 0;
85 }
86
87 HAPI int dead_init(void)
88 {
89         com_core_add_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
90         return 0;
91 }
92
93 HAPI int dead_fini(void)
94 {
95         com_core_del_event_callback(CONNECTOR_DISCONNECTED, evt_cb, NULL);
96         return 0;
97 }
98
99 /* End of a file */