4 * Copyright (c) 2013 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.
23 #include "core/list.h"
24 #include "core/common.h"
25 #include "core/coords.h"
26 #include "core/edbus-handler.h"
27 #include "shared/dbus.h"
30 #define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV))
32 /* rotation operation variable */
33 static c_list *r_head;
34 static const struct rotation_profile_ops *r_ops;
36 void add_rotation(const struct rotation_ops *ops) {
37 C_LIST_APPEND(r_head, (void*)ops);
40 void remove_rotation(const struct rotation_ops *ops) {
41 C_LIST_REMOVE(r_head, (void*)ops);
44 int broadcast_rotation_status(int last_notified_status) {
49 rot = r_ops->get_rotation_status();
51 if (last_notified_status == rot) {
55 snprintf(str_status, sizeof(str_status), "%d", rot);
57 r = broadcast_edbus_signal(COORD_PATH_ROTATION, COORD_INTERFACE_ROTATION,
58 COORD_SIGNAL_ROTATION_CHANGED, "i", arr);
59 _D("broadcast rotation signal: %d", rot);
61 _E("Failed: broadcast_edbus_signal()");
62 return last_notified_status;
68 static DBusMessage *edbus_get_degree(E_DBus_Object *obj, DBusMessage *message)
74 if (!CHECK_VALID_OPS(r_ops, r))
77 rot = r_ops->get_rotation_status();
81 reply = dbus_message_new_method_return(message);
82 dbus_message_iter_init_append(reply, &iter);
83 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &r);
87 static const struct edbus_method edbus_methods[] = {
88 { COORD_METHOD_ROTATION_DEGREE, NULL, NULL, edbus_get_degree },
89 /* Add methods here */
92 static void rotation_init(void *data)
96 struct rotation_ops *ops;
100 /* find valid profile */
101 C_LIST_FOREACH(r_head, elem, ops) {
107 if (!CHECK_VALID_OPS(r_ops, r)) {
108 _E("Can't find the valid rotation profile");
112 /* init dbus interface */
113 r = register_edbus_method(COORD_PATH_ROTATION, edbus_methods, ARRAY_SIZE(edbus_methods));
115 _E("fail to init edbus method(%d)", r);
120 static void rotation_exit(void *data)
124 struct rotation_ops *ops;
128 if (!CHECK_VALID_OPS(r_ops, r))
131 /* release profile */
132 C_LIST_FOREACH(r_head, elem, ops) {
141 static const struct coord_ops rotation_coord_ops = {
142 .priority = COORD_PRIORITY_NORMAL,
144 .init = rotation_init,
145 .exit = rotation_exit,
148 COORD_OPS_REGISTER(&rotation_coord_ops)