2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
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
10 //==========================================================================
12 * @file CicoSCInputController.cpp
14 * @brief This file is implementation of CicoSCInputController class
16 //==========================================================================
22 #include "CicoSCInputController.h"
23 #include "CicoSCWayland.h"
25 #include "CicoSCSwitch.h"
26 #include "CicoSCInputDev.h"
27 #include "ico_syc_error.h"
28 #include "ico_syc_msg_cmd_def.h"
29 #include "ico_syc_private.h"
30 #include "CicoSystemConfig.h"
32 #include "CicoSCCommand.h"
33 #include "CicoSCServer.h"
34 #include "CicoSCMessage.h"
36 //--------------------------------------------------------------------------
38 * @brief default constructor
40 //--------------------------------------------------------------------------
41 CicoSCInputController::CicoSCInputController()
43 CicoSCWayland* wayland = CicoSCWayland::getInstance();
44 wayland->addWaylandIF(ICO_WL_INPUT_MGR_CTRL_IF, this);
45 wayland->addWaylandIF(ICO_WL_EXINPUT_IF, this);
46 wayland->addWaylandIF(ICO_WL_INPUT_MGR_DEV_IF, this);
50 //--------------------------------------------------------------------------
54 //--------------------------------------------------------------------------
55 CicoSCInputController::~CicoSCInputController()
63 const vector<CicoSCInputDevConf*>& inputDevConfList =
64 CicoSystemConfig::getInstance()->getInputDevConfList();
65 vector<CicoSCInputDevConf*>::const_iterator itr;
66 itr = inputDevConfList.begin();
67 for (; itr != inputDevConfList.end(); ++itr) {
68 const CicoSCInputDevConf *iconf = const_cast<CicoSCInputDevConf*>(*itr);
69 CicoSCInputDev *device = new CicoSCInputDev();
71 device->devcie = iconf->name;
73 vector<CicoSCSwitchConf*>::const_iterator itr2;
74 itr2 = iconf->switchConfList.begin();
75 for (; itr2 != dconf->switchConfList.end(); ++itr2) {
76 const CicoSCSwitchConf *sconf = const_cast<CicoSCSwitchConf*>(*itr2);
78 CicoSCSwitch *sw = new CicoSCSwitch();
79 sw->swname = sconf->name;
80 sw->input = sconf->id;
81 devcie->switchList.push_back(sw);
92 //--------------------------------------------------------------------------
94 * @brief executes an input control process corresponding to the command
98 //--------------------------------------------------------------------------
100 CicoSCInputController::handleCommand(const CicoSCCommand *cmd)
102 ICO_TRA("CicoSCInputController::handleCommand Enter"
103 "(cmdid=0x%08x)", cmd->cmdid);
105 CicoSCCmdInputDevCtrlOpt *opt;
106 CicoSCCmdInputDevSettingOpt *set_opt;
108 switch (cmd->cmdid) {
109 case MSG_CMD_ADD_INPUT:
110 opt = static_cast<CicoSCCmdInputDevCtrlOpt*>(cmd->opt);
111 addInputApp(cmd->appid, opt->device, opt->input, opt->fix,
114 case MSG_CMD_DEL_INPUT:
115 opt = static_cast<CicoSCCmdInputDevCtrlOpt*>(cmd->opt);
116 delInputApp(cmd->appid, opt->device, opt->input);
118 case MSG_CMD_SET_REGION:
119 set_opt = static_cast<CicoSCCmdInputDevSettingOpt*>(cmd->opt);
120 setInputRegion(cmd->appid, set_opt->winname, set_opt->x, set_opt->y,
121 set_opt->width, set_opt->height,
122 set_opt->hotspot_x, set_opt->hotspot_y,
123 set_opt->cursor_x, set_opt->cursor_y,
124 set_opt->cursor_width, set_opt->cursor_height, set_opt->attr);
126 case MSG_CMD_UNSET_REGION:
127 set_opt = static_cast<CicoSCCmdInputDevSettingOpt*>(cmd->opt);
128 unsetInputRegion(cmd->appid, set_opt->winname, set_opt->x, set_opt->y,
129 set_opt->width, set_opt->height);
132 ICO_WRN("Unknown Command(0x%08x)", cmd->cmdid);
136 ICO_TRA("CicoSCInputController::handleCommand Leave");
139 //--------------------------------------------------------------------------
141 * @brief register input device control application
143 * @param [in] appid application id
144 * @param [in] device input device name
145 * @param [in] input input number
146 * @parma [in] fix fixed assign flag
147 * @parma [in] keycode assigned keycode value
149 //--------------------------------------------------------------------------
151 CicoSCInputController::addInputApp(const string &appid,
152 const string &device,
157 ICO_TRA("CicoSCInputController::addInputApp Enter"
158 "(appid=%s device=%s input=%d fix=%d keycode=%d)",
159 appid.c_str(), device.c_str(), input, fix, keycode);
161 CicoSCWlInputMgrIF::addInputApp(appid.c_str(), device.c_str(),
162 input, fix, keycode);
164 ICO_TRA("CicoSCInputController::addInputApp Leave(EOK)");
168 //--------------------------------------------------------------------------
170 * @brief unregister input device control application
172 * @param [in] appid application id
173 * @param [in] device input device name
174 * @param [in] input input number
176 //--------------------------------------------------------------------------
178 CicoSCInputController::delInputApp(const string &appid,
179 const string &device,
182 ICO_TRA("CicoSCInputController::delInputApp Enter"
183 "(appid=%s device=%s input=%d)",
184 appid.c_str(), device.c_str(), input);
186 CicoSCWlInputMgrIF::delInputApp(appid.c_str(), device.c_str(), input);
188 ICO_TRA("CicoSCInputController::delInputApp Leave(EOK)");
192 //--------------------------------------------------------------------------
194 * @brief set input region information
196 * @param [in] appid application id
197 * @param [in] winname window name
198 * @param [in] x region x positon
199 * @param [in] y region y positon
200 * @param [in] width region width
201 * @param [in] height region height
202 * @param [in] hotspot_x hotspot x position
203 * @param [in] hotspot_y hotspot y position
204 * @param [in] cursor_x cursor x position
205 * @param [in] cursor_y cursor y position
206 * @param [in] cursor_width cursor width
207 * @param [in] cursor_height cursor height
208 * @param [in] attr region attribute
210 //--------------------------------------------------------------------------
212 CicoSCInputController::setInputRegion(const string &appid,
213 const string &winname,
226 char target[ICO_SYC_MAX_LEN];
228 snprintf(target, ICO_SYC_MAX_LEN-1, "%s@%s", winname.c_str(), appid.c_str());
230 ICO_TRA("CicoSCInputController::setInputRegion Enter"
231 "(target=%s x=%d y=%d width=%d height=%d "
232 "hotspot=%d/%d cursor=%d/%d-%d/%d attr=%d)",
233 target, x, y, width, height, hotspot_x, hotspot_y,
234 cursor_x, cursor_y, cursor_width, cursor_height, attr);
236 CicoSCWlInputMgrIF::setInputRegion(target, x, y, width, height,
237 hotspot_x, hotspot_y, cursor_x, cursor_y,
238 cursor_width, cursor_height, attr);
240 ICO_TRA("CicoSCInputController::setInputRegion Leave(EOK)");
244 //--------------------------------------------------------------------------
246 * @brief unset input region information
248 * @param [in] appid application id
249 * @param [in] winname window name
250 * @param [in] x region x positon
251 * @param [in] y region y positon
252 * @param [in] width region width
253 * @param [in] height region height
255 //--------------------------------------------------------------------------
257 CicoSCInputController::unsetInputRegion(const string &appid,
258 const string &winname,
264 char target[ICO_SYC_MAX_LEN];
266 snprintf(target, ICO_SYC_MAX_LEN-1, "%s@%s", winname.c_str(), appid.c_str());
268 ICO_TRA("CicoSCInputController::unsetInputRegion Enter"
269 "(target=%s x=%d y=%d width=%d height=%d", target, x, y, width, height);
271 CicoSCWlInputMgrIF::unsetInputRegion(target, x, y, width, height);
273 ICO_TRA("CicoSCInputController::unsetInputRegion Leave(EOK)");
277 //--------------------------------------------------------------------------
279 * @brief callback to application for input switch information
281 * @param [in] data user data
282 * @param [in] ico_exinput wayland ico_exinput interface
283 * @param [in] device input device name
284 * @param [in] type input device type (as enum type)
285 * @param [in] swname input switch name
286 * @param [in] input input switch number
287 * @param [in] codename input code name
288 * @param [in] code input code number
290 //--------------------------------------------------------------------------
292 CicoSCInputController::capabilitiesCB(void *data,
293 struct ico_exinput *ico_exinput,
298 const char *codename,
301 ICO_TRA("CicoSCInputController::capabilitiesCB Enter",
302 "device=%s type=%s swname=%s input=%s codename=%s code=%d",
303 device, type, swname, input, codename, code);
305 // create CicoSCInputDev object
306 CicoSCInputDev *inputdev = findInputDev(device);
307 if (NULL == inputdev) {
308 inputdev = new CicoSCInputDev();
309 inputdev->device = device;
310 inputdev->type = type;
313 CicoSCSwitch *sw = findInputSwitch(device, input);
315 sw = new CicoSCSwitch();
317 sw->code.push_back(code);
318 sw->codename.push_back(codename);
324 CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
325 const CicoSCSwitchConf *swconf = NULL;
326 swconf = sysConf->findSwitchConfbyName(device, swname);
327 if (NULL != swconf) {
328 if (false == swconf->appid.empty()) {
329 addInputApp(swconf->appid, inputdev->device,
330 input,CicoSCSwitch::SWITCH_FIX, swconf->keycode);
335 ICO_TRA("CicoSCInputController::capabilitiesCB Leave");
338 //--------------------------------------------------------------------------
340 * @brief callback to application for input code information
342 * @param [in] data user data
343 * @param [in] ico_exinput wayland ico_exinput interface
344 * @param [in] device input device name
345 * @param [in] input input switch number
346 * @param [in] codename input code name
347 * @param [in] code input code number
349 //--------------------------------------------------------------------------
351 CicoSCInputController::codeCB(void *data,
352 struct ico_exinput *ico_exinput,
355 const char *codename,
358 ICO_TRA("CicoSCInputController::codeCB Enter"
359 "(device=%s input=%d codename=%s code=%d)",
360 device, input, codename, code);
362 CicoSCSwitch *sw = findInputSwitch(device, input);
364 ICO_ERR("codeCB: device=%s input=%d not found.");
368 if (sw->code.size() >= CicoSCSwitch::SWITCH_CODE_MAX) {
369 ICO_ERR("codeCB: device=%s input=%d number of codes overflow.");
373 for (unsigned int i = 0; i < sw->code.size(); ++i) {
374 if (sw->code[i] == code) {
375 ICO_WRN("codeCB: device=%s input=%d code=%d already exist.");
380 sw->code.push_back(code);
381 sw->codename.push_back(codename);
383 ICO_TRA("CicoSCInputController::codeCB Leave");
386 //--------------------------------------------------------------------------
388 * @brief callback to application for switch input
390 * @param [in] data user data
391 * @param [in] ico_exinput wayland ico_exinput interface
392 * @param [in] time input time of millisecond
393 * @param [in] device input device name
394 * @param [in] input input switch number
395 * @param [in] code input switch code
396 * @param [in] state Of/Off status
398 //--------------------------------------------------------------------------
400 CicoSCInputController::inputCB(void *data,
401 struct ico_exinput *ico_exinput,
408 ICO_TRA("CicoSCInputController::inputCB Enter"
409 "time=%d device=%s input=%d code=%d state=%d",
410 time, device, input, code, state);
413 CicoSCMessage *message = new CicoSCMessage();
414 message->addRootObject("command", ICO_SYC_EV_WIN_CREATE);
415 message->addArgObject("device", device);
416 message->addArgObject("time", time);
417 message->addArgObject("input", input);
418 message->addArgObject("code", code);
419 message->addArgObject("state", state);
420 CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
422 ICO_TRA("CicoSCInputController::inputCB Leave");
425 //--------------------------------------------------------------------------
427 * @brief callback to application for change input region
429 * @param [in] data user data
430 * @param [in] ico_input_mgr_dev wayland ico_exinput interface
431 * @param [in] region input regions
433 //--------------------------------------------------------------------------
435 CicoSCInputController::regionCB(void *data,
436 struct ico_input_mgr_device *ico_input_mgr_dev,
437 struct wl_array *region)
439 ICO_TRA("CicoSCInputController::regionCB Enter");
440 ICO_TRA("CicoSCInputController::regionCB Leave");
443 //--------------------------------------------------------------------------
445 * @brief find input device information
447 * @param [in] device input device name
449 * @return CicoSCInputDev instance on found, NULL on not found
451 //--------------------------------------------------------------------------
453 CicoSCInputController::findInputDev(const char *device)
455 vector<CicoSCInputDev*>::iterator itr;
456 itr = m_inputDevList.begin();
457 for (; itr != m_inputDevList.end(); ++itr) {
458 CicoSCInputDev* inputdev = const_cast<CicoSCInputDev*>(*itr);
459 if (inputdev->device == device) {
466 //--------------------------------------------------------------------------
468 * @brief find input device switch information
470 * @param [in] device input device name
471 * @param [in] input input number
473 * @return CicoSCSwitch instance on found, NULL on not found
475 //--------------------------------------------------------------------------
477 CicoSCInputController::findInputSwitch(const char *device, int input)
479 const CicoSCInputDev *inputdev = findInputDev(device);
480 if (NULL == inputdev) {
484 vector<CicoSCSwitch*>::const_iterator itr;
485 itr = inputdev->switchList.begin();
486 for (; itr != inputdev->switchList.end(); ++itr) {
487 CicoSCSwitch* sw = const_cast<CicoSCSwitch*>(*itr);
488 if (sw->input == input) {
494 // vim:set expandtab ts=4 sw=4: