Merge branch 'devel/tizen' into tizen
[platform/core/system/sensord.git] / src / sensorctl / injector_context_orientation.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2016 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
20 #include <stdio.h>
21 #include <glib.h>
22 #include <gio/gio.h>
23 #include "log.h"
24 #include "dbus_util.h"
25 #include "injector.h"
26
27 #define CONTEXT_ORIENTATION_SIGNAL      "orientation"
28
29 class injector_context_orientation : public injector {
30 public:
31         injector_context_orientation(sensor_type_t sensor_type, const char *event_name);
32         virtual ~injector_context_orientation() {}
33
34         bool inject(int argc, char *argv[]);
35 };
36
37 injector_context_orientation::injector_context_orientation(sensor_type_t sensor_type, const char *event_name)
38 : injector(sensor_type, event_name)
39 {
40 }
41
42 bool injector_context_orientation::inject(int argc, char *argv[])
43 {
44         GVariant *variant;
45
46         RETVM_IF(argc <= INJECTOR_ARGC, false, "Invalid argument\n");
47
48         variant = make_variant_int(argc - INJECTOR_ARGC, &argv[INJECTOR_ARGC]);
49         RETVM_IF(!variant, false, "Cannot make variant\n");
50
51         dbus_emit_signal(NULL,
52                         (gchar *)SENSORD_OBJ_PATH,
53                         (gchar *)SENSORD_INTERFACE_NAME,
54                         (gchar *)CONTEXT_ORIENTATION_SIGNAL,
55                         variant,
56                         NULL);
57
58         _I("Set up options to wristup:");
59         for (int i = 0; i < argc - INJECTOR_ARGC; ++i)
60                 _I("option %d: %s\n", i, argv[i]);
61
62         return true;
63 }
64
65 REGISTER_INJECTOR(CONTEXT_SENSOR, CONTEXT_ORIENTATION_SIGNAL, injector_context_orientation)