3b014d319ca102e3b11926faccea55287b86e2d1
[platform/upstream/connman.git] / plugins / iospm.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #define CONNMAN_API_SUBJECT_TO_CHANGE
27 #include <connman/plugin.h>
28 #include <connman/notifier.h>
29 #include <connman/dbus.h>
30 #include <connman/log.h>
31
32 #define IOSPM_SERVICE           "com.intel.mid.ospm"
33 #define IOSPM_INTERFACE         IOSPM_SERVICE ".Comms"
34
35 #define IOSPM_BLUETOOTH         "/com/intel/mid/ospm/bluetooth"
36 #define IOSPM_FLIGHT_MODE       "/com/intel/mid/ospm/flight_mode"
37
38 static DBusConnection *connection;
39
40 static void send_indication(const char *path, connman_bool_t enabled)
41 {
42         DBusMessage *message;
43         const char *method;
44
45         DBG("path %s enabled %d", path, enabled);
46
47         if (enabled == TRUE)
48                 method = "IndicateStart";
49         else
50                 method = "IndicateStop";
51
52         message = dbus_message_new_method_call(IOSPM_SERVICE, path,
53                                                 IOSPM_INTERFACE, method);
54         if (message == NULL)
55                 return;
56
57         dbus_message_set_no_reply(message, TRUE);
58
59         dbus_connection_send(connection, message, NULL);
60
61         dbus_message_unref(message);
62 }
63
64 static void iospm_service_enabled(enum connman_service_type type,
65                                                 connman_bool_t enabled)
66 {
67         switch (type) {
68         case CONNMAN_SERVICE_TYPE_UNKNOWN:
69         case CONNMAN_SERVICE_TYPE_SYSTEM:
70         case CONNMAN_SERVICE_TYPE_ETHERNET:
71         case CONNMAN_SERVICE_TYPE_WIFI:
72         case CONNMAN_SERVICE_TYPE_CELLULAR:
73         case CONNMAN_SERVICE_TYPE_GPS:
74         case CONNMAN_SERVICE_TYPE_VPN:
75         case CONNMAN_SERVICE_TYPE_GADGET:
76                 break;
77         case CONNMAN_SERVICE_TYPE_BLUETOOTH:
78                 send_indication(IOSPM_BLUETOOTH, enabled);
79                 break;
80         }
81 }
82
83 static void iospm_offline_mode(connman_bool_t enabled)
84 {
85         send_indication(IOSPM_FLIGHT_MODE, enabled);
86 }
87
88 static struct connman_notifier iospm_notifier = {
89         .name           = "iospm",
90         .priority       = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
91         .service_enabled= iospm_service_enabled,
92         .offline_mode   = iospm_offline_mode,
93 };
94
95 static int iospm_init(void)
96 {
97         connection = connman_dbus_get_connection();
98
99         return connman_notifier_register(&iospm_notifier);
100 }
101
102 static void iospm_exit(void)
103 {
104         connman_notifier_unregister(&iospm_notifier);
105
106         dbus_connection_unref(connection);
107 }
108
109 CONNMAN_PLUGIN_DEFINE(ospm, "Intel OSPM notification plugin", VERSION,
110                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, iospm_init, iospm_exit)