Add support for sending flight mode indication
[connman] / plugins / iospm.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  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 ".MMF"
34
35 #define IOSPM_FLIGHT_MODE       "/com/intel/mid/ospm/flight_mode"
36
37 static DBusConnection *connection;
38
39 static void iospm_device_enabled(enum connman_device_type type,
40                                                 connman_bool_t enabled)
41 {
42         DBG("type %d enabled %d", type, enabled);
43 }
44
45 static void iospm_offline_mode(connman_bool_t enabled)
46 {
47         DBusMessage *message;
48         const char *method;
49
50         DBG("enabled %d", enabled);
51
52         if (enabled == TRUE)
53                 method = "IndicateStart";
54         else
55                 method = "IndicateStop";
56
57         message = dbus_message_new_method_call(IOSPM_SERVICE,
58                                 IOSPM_FLIGHT_MODE, IOSPM_INTERFACE, method);
59         if (message == NULL)
60                 return;
61
62         dbus_message_set_no_reply(message, TRUE);
63
64         dbus_connection_send(connection, message, NULL);
65
66         dbus_message_unref(message);
67 }
68
69 static struct connman_notifier iospm_notifier = {
70         .name           = "iospm",
71         .priority       = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
72         .device_enabled = iospm_device_enabled,
73         .offline_mode   = iospm_offline_mode,
74 };
75
76 static int iospm_init(void)
77 {
78         connection = connman_dbus_get_connection();
79
80         return connman_notifier_register(&iospm_notifier);
81 }
82
83 static void iospm_exit(void)
84 {
85         connman_notifier_unregister(&iospm_notifier);
86
87         dbus_connection_unref(connection);
88 }
89
90 CONNMAN_PLUGIN_DEFINE(ospm, "Intel OSPM notification plugin", VERSION,
91                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, iospm_init, iospm_exit)