• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *
3  * Copyright 2012 BMW Car IT GmbH
4  *
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 #include "ilm_control.h"
20 #include "ilm_input.h"
21 #include "LMControl.h"
22 #include "Expression.h"
23 #include "ExpressionInterpreter.h"
24 #include <iostream>
25 #include <sstream>
26 #include <iomanip>
27 #include <vector>
28 #include <map>
29 #include <algorithm>
30 #include <iterator>
31 #include <cstring>
32 #include <signal.h> // signal
33 #include <unistd.h> // alarm
34 
35 using namespace std;
36 
37 
38 #define COMMAND(text) COMMAND2(__COUNTER__,text)
39 
40 #define COMMAND2(x,y) COMMAND3(x,y)
41 
42 #define COMMAND3(funcNumber, text) \
43     void func_ ## funcNumber(Expression* input); \
44     static const bool reg_ ## funcNumber = \
45         ExpressionInterpreter::addExpression(func_ ## funcNumber, text); \
46     void func_ ## funcNumber(Expression* input)
47 
48 //=============================================================================
49 COMMAND3(50,"get input devices with pointer|keyboard|touch|all")
50 //=============================================================================
51 {
52     t_ilm_uint num_seats = 0;
53     t_ilm_string *seats;
54     ilmInputDevice mask = 0;
55 
56     if (input->contains("pointer"))
57         mask |= ILM_INPUT_DEVICE_POINTER;
58     if (input->contains("keyboard"))
59         mask |= ILM_INPUT_DEVICE_KEYBOARD;
60     if (input->contains("touch"))
61         mask |= ILM_INPUT_DEVICE_TOUCH;
62     if (input->contains("all"))
63         mask |= ILM_INPUT_DEVICE_ALL;
64 
65     ilmErrorTypes callResult = ilm_getInputDevices(mask, &num_seats, &seats);
66     if (ILM_SUCCESS != callResult)
67     {
68         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
69         cout << "Failed to get input devices for mask " << input->getUint("mask") << "\n";
70         return;
71     }
72 
73     for(unsigned int i = 0; i < num_seats; i++) {
74         cout << seats[i] << endl;
75         free(seats[i]);
76     }
77 
78     free(seats);
79 }
80 
81 //=============================================================================
82 COMMAND3(51,"set|unset surfaces [<idarray>] input focus pointer|keyboard|touch|all")
83 //=============================================================================
84 {
85     t_ilm_surface *surfaceIDs;
86     t_ilm_uint num_surfaces;
87     ilmInputDevice bitmask = 0;
88     t_ilm_bool is_set;
89 
90     if (input->contains("set"))
91         is_set = ILM_TRUE;
92     else
93         is_set = ILM_FALSE;
94 
95     if (input->contains("pointer"))
96         bitmask |= ILM_INPUT_DEVICE_POINTER;
97     if (input->contains("keyboard"))
98         bitmask |= ILM_INPUT_DEVICE_KEYBOARD;
99     if (input->contains("touch"))
100         bitmask |= ILM_INPUT_DEVICE_TOUCH;
101     if (input->contains("all"))
102         bitmask |= ILM_INPUT_DEVICE_ALL;
103 
104     input->getUintArray("idarray", &surfaceIDs, &num_surfaces);
105 
106     cout << "setting input focus in LayerManagerControl" << endl;
107     ilmErrorTypes callResult =
108         ilm_setInputFocus(surfaceIDs, num_surfaces, bitmask, is_set);
109     if (ILM_SUCCESS != callResult)
110     {
111         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << endl;
112         cout << "Failed to set input focus" << endl;
113     }
114     else
115     {
116         cout << "LayerManagerService succeeded" << endl;
117     }
118 
119     delete[] surfaceIDs;
120 }
121 
122 //=============================================================================
123 COMMAND3(52,"get input focus")
124 //=============================================================================
125 {
126     (void) input;
127     t_ilm_surface *surfaceIDs;
128     ilmInputDevice *bitmasks;
129     t_ilm_uint num_ids = 0;
130     ilmErrorTypes callResult = ilm_getInputFocus(&surfaceIDs, &bitmasks, &num_ids);
131     if (ILM_SUCCESS != callResult)
132     {
133         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << endl;
134         cout << "Failed to get input focus" << endl;
135     }
136     else
137     {
138         for (unsigned int i = 0; i < num_ids; i++)
139         {
140             cout << "surface " << surfaceIDs[i] << ": "
141                  << ((bitmasks[i] & ILM_INPUT_DEVICE_POINTER) ? "pointer " : "")
142                  << ((bitmasks[i] & ILM_INPUT_DEVICE_KEYBOARD) ? "keyboard " : "")
143                  << ((bitmasks[i] & ILM_INPUT_DEVICE_TOUCH) ? "touch" : "")
144                  << endl;
145         }
146     }
147     free(surfaceIDs);
148     free(bitmasks);
149 }
150 
151 //=============================================================================
152 COMMAND3(53,"get input device <name> capabilities")
153 //=============================================================================
154 {
155     ilmInputDevice bitmask;
156     ilmErrorTypes callResult =
157         ilm_getInputDeviceCapabilities((char*)input->getString("name").c_str(), &bitmask);
158     if (ILM_SUCCESS != callResult)
159     {
160         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
161         cout << "Failed to get capabilities for device " << input->getString("name") << "\n";
162         return;
163     }
164     if (bitmask & ILM_INPUT_DEVICE_POINTER)
165         cout << "pointer" << endl;
166     if (bitmask & ILM_INPUT_DEVICE_KEYBOARD)
167         cout << "keyboard" << endl;
168     if (bitmask & ILM_INPUT_DEVICE_TOUCH)
169         cout << "touch" << endl;
170 }
171 
172 //=============================================================================
173 COMMAND3(54,"set surface <surfaceid> input acceptance to [<namearray>]")
174 //=============================================================================
175 {
176 	ilmErrorTypes callResult = ILM_FAILED;
177     t_ilm_string *array = NULL;
178     t_ilm_uint count = 0;
179     t_ilm_surface surfaceid = input->getUint("surfaceid");
180     string str;
181     size_t pos;
182      unsigned int i;
183 
184      if (input->contains("namearray")) {
185          // Generate a string array
186          str = input->getString("namearray");
187          count = std::count(str.begin(), str.end(), ',') + 1;
188          array = (t_ilm_string *)calloc(count, sizeof *array);
189          if (array == NULL) {
190              cerr << "Failed to allocate memory for string array" << endl;
191              return;
192          }
193 
194          i = 0;
195          while(true) {
196              pos = str.find(",");
197              string token = str.substr(0, pos);
198              array[i] = strdup(token.c_str());
199              if (array[i] == NULL) {
200                  cerr << "Failed to duplicate string: " << token << endl;
201                  for (unsigned int j = 0; j < i; j++)
202                      free(array[i]);
203                  free(array);
204                  return;
205              }
206              str.erase(0, pos + 1);
207              i++;
208              if (pos == std::string::npos)
209                  break;
210          }
211 
212          callResult = ilm_setInputAcceptanceOn(surfaceid, count, array);
213 
214          for (unsigned int i = 0; i < count; i++)
215              free(array[i]);
216          free(array);
217      } else {
218          callResult = ilm_setInputAcceptanceOn(surfaceid, 0, NULL);
219      }
220 
221     if (ILM_SUCCESS != callResult)
222     {
223         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult)
224              << endl;
225         cout << "Failed to set acceptance for surface " << surfaceid << endl;
226     }
227 }
228 
229 //=============================================================================
230 COMMAND3(55,"get surface <surfaceid> input acceptance")
231 //=============================================================================
232 {
233     t_ilm_string *array = NULL;
234     t_ilm_uint num_seats;
235     t_ilm_surface surfaceid = input->getUint("surfaceid");
236 
237     ilmErrorTypes callResult = ilm_getInputAcceptanceOn(surfaceid, &num_seats,
238                                                         &array);
239     if (ILM_SUCCESS != callResult)
240     {
241         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult)
242              << endl;
243         cout << "Failed to get acceptance for surface " << surfaceid << endl;
244         return;
245     }
246 
247     for (unsigned int i = 0; i < num_seats; i++) {
248         cout << array[i] << endl;
249         free(array[i]);
250     }
251     free(array);
252 }
253