Fixed some RPMlint errors - group name, duplicate files, etc.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_uxf_inputdev.c
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   heade for input device
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include    <stdio.h>
16 #include    <stdlib.h>
17 #include    <unistd.h>
18 #include    <string.h>
19 #include    <errno.h>
20
21 #include    "ico_uxf.h"
22 #include    "ico_uxf_private.h"
23 #include    "ico_input_mgr-client-protocol.h"
24
25 extern Ico_Uxf_Api_Mng         gIco_Uxf_Api_Mng;
26
27 /*--------------------------------------------------------------------------*/
28 /**
29  * @brief   ico_uxf_inputdev_attribute_get: get input device attribute
30  *
31  * @param[in]   devidx          input device index (0-)
32  * @return      result
33  * @retval      !=NULL          success(input device attribute address)
34  * @retval      ==NULL          error(device dose not exist)
35  */
36 /*--------------------------------------------------------------------------*/
37 ICO_APF_API Ico_Uxf_InputDev *
38 ico_uxf_inputdev_attribute_get(const int devidx)
39 {
40     Ico_Uxf_InputDev    *pdev;
41     int                 idx;
42
43     uifw_trace("ico_uxf_inputdev_attribute_get: Enter(%d)", devidx);
44
45     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
46         uifw_warn("ico_uxf_window_layer: Leave(ESRCH)");
47         return NULL;
48     }
49
50     pdev = gIco_Uxf_Api_Mng.InputDev;
51     idx = 0;
52     while ((pdev != NULL) && (idx < devidx))    {
53         idx ++;
54         pdev = pdev->next;
55     }
56
57     if ((pdev == NULL) || (idx != devidx))  {
58         uifw_trace("ico_uxf_inputdev_attribute_get: Leave(ENOENT)");
59         return NULL;
60     }
61
62     uifw_trace("ico_uxf_inputdev_attribute_get: Leave(EOK, device=%s)", pdev->device);
63     return pdev;
64 }
65
66 /*--------------------------------------------------------------------------*/
67 /**
68  * @brief   ico_uxf_inputsw_attribute_get: get input switch attribute
69  *
70  * @param[in]   inputdev        input device attribute
71  * @param[in]   swidx           input switch index (0-)
72  * @return      result
73  * @retval      !=NULL          success(input switch attribute address)
74  * @retval      ==NULL          error(device dose not exist)
75  */
76 /*--------------------------------------------------------------------------*/
77 ICO_APF_API Ico_Uxf_InputSw *
78 ico_uxf_inputsw_attribute_get(Ico_Uxf_InputDev *inputdev, const int swidx)
79 {
80     Ico_Uxf_InputSw     *psw;
81     int                 idx;
82
83     uifw_trace("ico_uxf_inputsw_attribute_get: Enter(%s,%d)",
84                inputdev ? inputdev->device : "(NULL)", swidx);
85
86     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
87         uifw_warn("ico_uxf_inputsw_attribute_get: Leave(ESRCH)");
88         return NULL;
89     }
90     if ((inputdev == NULL) || (swidx < 0) || (swidx >= inputdev->numInputSw))   {
91         uifw_warn("ico_uxf_inputsw_attribute_get: Leave(device ENOENT)");
92         return NULL;
93     }
94
95     psw = inputdev->inputSw;
96     idx = 0;
97     while ((psw != NULL) && (idx < swidx))  {
98         idx ++;
99         psw = psw->next;
100     }
101
102     if ((psw == NULL) || (idx != swidx))   {
103         uifw_warn("ico_uxf_inputsw_attribute_get: Leave(switch ENOENT)");
104         return NULL;
105     }
106
107     uifw_trace("ico_uxf_inputsw_attribute_get: Leave(EOK, switch=%s.%s)",
108                inputdev->device, psw->swname);
109     return psw;
110 }
111
112 /*--------------------------------------------------------------------------*/
113 /**
114  *  @brief  Send request to Multi Input Manager
115  *
116  *  @param[in]  add         switch add(=1)/delete(=0)
117  *  @param[in]  appid       target application id
118  *  @param[in]  device      target input device name
119  *  @param[in]  input       target input switch number
120  *  @param[in]  keycode     emulated keyboard key-code
121  *  @return     result status
122  *  @retval     ICO_UXF_EOK success(cullentry always success)
123  */
124 /*--------------------------------------------------------------------------*/
125 ICO_APF_API int
126 ico_uxf_input_control(const int add, const char *appid,
127                       const char *device, const int input, const int keycode)
128 {
129     apfw_trace("ico_uxf_input_control: input switch %s %s %s.%d(%d)",
130                add ? "add" : "del", appid ? appid : "all-app",
131                device ? device : "all-device", input, keycode);
132
133     if (add)    {
134         ico_input_mgr_control_add_input_app(gIco_Uxf_Api_Mng.Wayland_InputMgr, appid,
135                                             device, input, 0, keycode);
136     }
137     else    {
138         ico_input_mgr_control_del_input_app(gIco_Uxf_Api_Mng.Wayland_InputMgr, appid,
139                                             device, input);
140     }
141     return ICO_UXF_EOK;
142 }
143