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