Add pwm set_polarity & get_polarity functions 94/129894/2
authorjino.cho <jino.cho@samsung.com>
Thu, 18 May 2017 08:31:20 +0000 (17:31 +0900)
committerjino.cho <jino.cho@samsung.com>
Thu, 18 May 2017 09:54:37 +0000 (18:54 +0900)
Change-Id: I39edddd0446a490e2d2eecca249d3399a0584972
Signed-off-by: jino.cho <jino.cho@samsung.com>
src/daemon/peripheral_bus.c
src/daemon/peripheral_bus_pwm.c
src/daemon/peripheral_bus_pwm.h
src/daemon/peripheral_io.xml

index 42c28f5..06c206b 100644 (file)
@@ -436,6 +436,64 @@ gboolean handle_pwm_get_duty_cycle(
        return true;
 }
 
+gboolean handle_pwm_set_polarity(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint polarity,
+               gpointer user_data)
+{
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_pwm_data_h pwm_handle = GUINT_TO_POINTER(handle);
+       const gchar *id;
+
+       /* Handle validation */
+       if (!pwm_handle || !pwm_handle->client_info.id) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       } else {
+               id = g_dbus_method_invocation_get_sender(invocation);
+               if (strcmp(pwm_handle->client_info.id, id)) {
+                       _E("Invalid access, handle id : %s, current id : %s", pwm_handle->client_info.id, id);
+                       ret = PERIPHERAL_ERROR_INVALID_OPERATION;
+               } else
+                       ret = peripheral_bus_pwm_set_polarity(pwm_handle, polarity);
+       }
+
+       peripheral_io_gdbus_pwm_complete_set_polarity(pwm, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_get_polarity(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_pwm_data_h pwm_handle = GUINT_TO_POINTER(handle);
+       const gchar *id;
+       int polarity = 0;
+
+       /* Handle validation */
+       if (!pwm_handle || !pwm_handle->client_info.id) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       } else {
+               id = g_dbus_method_invocation_get_sender(invocation);
+               if (strcmp(pwm_handle->client_info.id, id)) {
+                       _E("Invalid access, handle id : %s, current id : %s", pwm_handle->client_info.id, id);
+                       ret = PERIPHERAL_ERROR_INVALID_OPERATION;
+               } else
+                       ret = peripheral_bus_pwm_get_polarity(pwm_handle, &polarity);
+       }
+
+       peripheral_io_gdbus_pwm_complete_get_polarity(pwm, invocation, polarity, ret);
+
+       return true;
+}
+
 gboolean handle_pwm_set_enable(
                PeripheralIoGdbusPwm *pwm,
                GDBusMethodInvocation *invocation,
@@ -903,6 +961,14 @@ static gboolean __pwm_init(peripheral_bus_s *pb_data)
                        G_CALLBACK(handle_pwm_get_duty_cycle),
                        pb_data);
        g_signal_connect(pb_data->pwm_skeleton,
+                       "handle-set-polarity",
+                       G_CALLBACK(handle_pwm_set_polarity),
+                       pb_data);
+       g_signal_connect(pb_data->pwm_skeleton,
+                       "handle-get-polarity",
+                       G_CALLBACK(handle_pwm_get_polarity),
+                       pb_data);
+       g_signal_connect(pb_data->pwm_skeleton,
                        "handle-set-enable",
                        G_CALLBACK(handle_pwm_set_enable),
                        pb_data);
index 993cf1a..0fff255 100644 (file)
@@ -149,6 +149,16 @@ int peripheral_bus_pwm_get_duty_cycle(pb_pwm_data_h pwm, int *duty_cycle)
        return pwm_get_duty_cycle(pwm->device, pwm->channel, duty_cycle);
 }
 
+int peripheral_bus_pwm_set_polarity(pb_pwm_data_h pwm, int polarity)
+{
+       return pwm_set_polarity(pwm->device, pwm->channel, (pwm_polarity_e)polarity);
+}
+
+int peripheral_bus_pwm_get_polarity(pb_pwm_data_h pwm, int *polarity)
+{
+       return pwm_get_polarity(pwm->device, pwm->channel, (pwm_polarity_e*)polarity);
+}
+
 int peripheral_bus_pwm_set_enable(pb_pwm_data_h pwm, bool enable)
 {
        return pwm_set_enable(pwm->device, pwm->channel, enable);
index 3e528a8..a98e3ea 100644 (file)
@@ -23,6 +23,8 @@ int peripheral_bus_pwm_set_period(pb_pwm_data_h pwm, int period);
 int peripheral_bus_pwm_get_period(pb_pwm_data_h pwm, int *period);
 int peripheral_bus_pwm_set_duty_cycle(pb_pwm_data_h pwm, int duty_cycle);
 int peripheral_bus_pwm_get_duty_cycle(pb_pwm_data_h pwm, int *duty_cycle);
+int peripheral_bus_pwm_set_polarity(pb_pwm_data_h pwm, int polarity);
+int peripheral_bus_pwm_get_polarity(pb_pwm_data_h pwm, int *polarity);
 int peripheral_bus_pwm_set_enable(pb_pwm_data_h pwm, bool enable);
 int peripheral_bus_pwm_get_enable(pb_pwm_data_h pwm, bool *enable);
 
index 57ad78d..abc3679 100644 (file)
                        <arg type="i" name="duty_cycle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="SetPolarity">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="polarity" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="GetPolarity">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="polarity" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
                <method name="SetEnable">
                        <arg type="u" name="handle" direction="in"/>
                        <arg type="b" name="enable" direction="in"/>