Initialize Tizen 2.3
[framework/system/deviced.git] / src / usb / usb-client-dbus.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <vconf.h>
20 #include "usb-client.h"
21 #include "core/edbus-handler.h"
22
23 #define CHANGE_USB_MODE "ChangeUsbMode"
24
25 static void change_usb_client_mode(void *data, DBusMessage *msg)
26 {
27         DBusError err;
28         int mode, debug;
29
30         if (dbus_message_is_signal(msg, DEVICED_INTERFACE_USB, CHANGE_USB_MODE) == 0) {
31                 _E("The signal is not for changing usb mode");
32                 return;
33         }
34
35         dbus_error_init(&err);
36
37         if (dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &mode, DBUS_TYPE_INVALID) == 0) {
38                 _E("FAIL: dbus_message_get_args");
39                 goto out;
40         }
41
42         switch (mode){
43         case SET_USB_DEFAULT:
44         case SET_USB_RNDIS:
45         case SET_USB_RNDIS_DIAG:
46                 debug = 0;
47                 break;
48         case SET_USB_SDB:
49         case SET_USB_SDB_DIAG:
50         case SET_USB_RNDIS_SDB:
51                 debug = 1;
52                 break;
53         default:
54                 _E("(%d) is unknown usb mode", mode);
55                 goto out;
56         }
57
58         if (vconf_set_int(VCONFKEY_USB_SEL_MODE, mode) != 0)
59                 _E("Failed to set usb mode (%d)", mode);
60
61         if (vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, debug) != 0)
62                 _E("Failed to set usb debug toggle (%d)", debug);
63
64 out:
65         dbus_error_free(&err);
66         return;
67 }
68
69
70 int register_usb_client_change_request(void)
71 {
72         return register_edbus_signal_handler(DEVICED_PATH_USB,
73                         DEVICED_INTERFACE_USB,
74                         CHANGE_USB_MODE, change_usb_client_mode);
75 }
76