4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include <sys/types.h>
30 #include <device-node.h>
34 #include "core/common.h"
35 #include "core/devices.h"
36 #include "core/device-handler.h"
37 #include "core/device-notifier.h"
38 #include "core/edbus-handler.h"
39 #include "display/poll.h"
41 #define SIGNAL_EARJACK_STATE "ChangedEarjack"
43 static int earjack_status = 0;
45 static void earjack_send_broadcast(int status)
54 _I("broadcast earjack status %d", status);
56 snprintf(str_status, sizeof(str_status), "%d", status);
59 broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
60 SIGNAL_EARJACK_STATE, "i", arr);
63 static void earjack_chgdet_cb(void *data)
71 ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val);
73 _E("failed to get status");
77 _I("jack - earjack changed %d", val);
78 vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val);
79 earjack_send_broadcast(val);
81 extcon_set_count(EXTCON_EARJACK);
82 internal_pm_change_state(LCD_NORMAL);
86 static DBusMessage *dbus_get_status(E_DBus_Object *obj, DBusMessage *msg)
93 _D("get hall status %d", val);
95 reply = dbus_message_new_method_return(msg);
96 dbus_message_iter_init_append(reply, &iter);
97 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &val);
101 static const struct edbus_method edbus_methods[] = {
102 { "getstatus", NULL, "i", dbus_get_status },
103 /* Add methods here */
106 static void earjack_init(void *data)
110 if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val) == 0) {
112 extcon_set_count(EXTCON_EARJACK);
113 vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val);
116 /* init dbus interface */
117 ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods));
119 _E("fail to init edbus method(%d)", ret);
122 static int earjack_get_status(void)
124 return earjack_status;
127 static int earjack_execute(void *data)
129 earjack_chgdet_cb(data);
133 static const struct device_ops earjack_device_ops = {
134 .priority = DEVICE_PRIORITY_NORMAL,
136 .init = earjack_init,
137 .status = earjack_get_status,
138 .execute = earjack_execute,
141 DEVICE_OPS_REGISTER(&earjack_device_ops)