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 CicoSCVInfoManager.cpp
14 * @brief This file implementation of CicoSCVInfoManager class
16 //==========================================================================
23 #include <ico_dbus_amb_efl.h>
24 #include "CicoSCVInfoManager.h"
25 #include "CicoSystemConfig.h"
27 #include "CicoSCVInfo.h"
29 //==========================================================================
30 // private static variable
31 //==========================================================================
32 CicoSCVInfoManager* CicoSCVInfoManager::ms_myInstance = NULL;
33 int CicoSCVInfoManager::ms_ecoreEvType= 0;
34 dbus_type CicoSCVInfoManager::ms_dbusTypes[ICO_TYPE_MAX];
35 int CicoSCVInfoManager::ms_retryCnt = 0;
37 //--------------------------------------------------------------------------
39 * @brief default constructor
41 //--------------------------------------------------------------------------
42 CicoSCVInfoManager::CicoSCVInfoManager()
43 : m_initialized(false)
45 ms_dbusTypes[ICO_TYPE_UNKNOW] = DBUS_TYPE_INT32;
46 ms_dbusTypes[ICO_TYPE_BOOLEAN] = DBUS_TYPE_BOOLEAN;
47 ms_dbusTypes[ICO_TYPE_INT8] = DBUS_TYPE_BYTE;
48 ms_dbusTypes[ICO_TYPE_UINT8] = DBUS_TYPE_BYTE;
49 ms_dbusTypes[ICO_TYPE_INT16] = DBUS_TYPE_INT16;
50 ms_dbusTypes[ICO_TYPE_UINT16] = DBUS_TYPE_UINT16;
51 ms_dbusTypes[ICO_TYPE_INT32] = DBUS_TYPE_INT32;
52 ms_dbusTypes[ICO_TYPE_UINT32] = DBUS_TYPE_UINT32;
53 ms_dbusTypes[ICO_TYPE_INT64] = DBUS_TYPE_INT64;
54 ms_dbusTypes[ICO_TYPE_UINT64] = DBUS_TYPE_UINT64;
55 ms_dbusTypes[ICO_TYPE_DOUBLE] = DBUS_TYPE_DOUBLE;
56 ms_dbusTypes[ICO_TYPE_STRING] = DBUS_TYPE_STRING;
58 ms_ecoreEvType = ecore_event_type_new();
60 CicoSCVInfoManager::ms_myInstance = this;
63 //--------------------------------------------------------------------------
67 //--------------------------------------------------------------------------
68 CicoSCVInfoManager::~CicoSCVInfoManager()
70 CicoSCVInfoManager::ms_myInstance = NULL;
73 //--------------------------------------------------------------------------
75 * @brief get instance of CicoSystemConfig
77 * @return pointer of CicoSystemConfig object
79 //--------------------------------------------------------------------------
81 CicoSCVInfoManager::getInstance(void)
83 if (NULL == ms_myInstance) {
84 ms_myInstance = new CicoSCVInfoManager();
89 //--------------------------------------------------------------------------
91 * @brief startup communication of vehicle information
94 * @retval true success
97 //--------------------------------------------------------------------------
99 CicoSCVInfoManager::startup(void)
101 ICO_TRA("CicoSCVInfoManager::startup Enter");
103 if (true == m_initialized) {
104 ICO_DBG("already initialized.");
105 ICO_TRA("CicoSCVInfoManager::startup Leave(true)");
108 ICO_DBG("called: ico_dbus_amb_start");
109 int ret = ico_dbus_amb_start();
111 ICO_ERR("ico_dbus_amb_start failed. ret=%d", ret);
112 ICO_TRA("CicoSCVInfoManager::startup Leave(false)");
116 m_initialized = true;
121 ICO_TRA("CicoSCVInfoManager::startup Leave(true)");
125 //--------------------------------------------------------------------------
127 * @brief teardown communication of vehicle information
130 * @retval true success
131 * @retval false error
133 //--------------------------------------------------------------------------
135 CicoSCVInfoManager::teardown(void)
137 ICO_TRA("CicoSCVInfoManager::teardown Enter");
139 if (false == m_initialized) {
140 ICO_DBG("not initialized.");
141 ICO_TRA("CicoSCVInfoManager::teardown Leave(true)");
144 m_initialized = false;
148 ICO_DBG("called: ico_dbus_amb_end");
149 int ret = ico_dbus_amb_end();
151 ICO_ERR("ico_dbus_amb_end faile. ret=%d", ret);
152 ICO_TRA("CicoSCVInfoManager::teardown Leave(false)");
156 ICO_TRA("CicoSCVInfoManager::teardown Leave(true)");
160 //--------------------------------------------------------------------------
162 * @brief get ecore event type of changed vehicle information
164 * @return ecore event type
166 //--------------------------------------------------------------------------
168 CicoSCVInfoManager::getEcoreEvType(void)
170 return ms_ecoreEvType;
173 //--------------------------------------------------------------------------
175 * @brief get vehicle information
177 * @param [in] property vehicle information property
180 * @retval true success
181 * @retval false error
183 //--------------------------------------------------------------------------
185 CicoSCVInfoManager::getVehicleInfo(int property)
187 ICO_TRA("CicoSCVInfoManager::getVehicleInfo Enter(prop=%d)", property);
189 if (false == m_initialized) {
190 ICO_DBG("not initialized.");
191 ICO_TRA("CicoSCVInfoManager::getVehicleInfo Leave(false)");
195 CicoSystemConfig* sysconf = CicoSystemConfig::getInstance();
196 CicoSCVehicleInfoConf* viconf = sysconf->getVehicleInfoConf();
197 std::map<int, CicoSCVIPropertyConf*>::iterator itr;
198 itr = viconf->properties.find(property);
199 if (itr == viconf->properties.end()) {
200 ICO_WRN("not found propetry(%d)", property);
204 ICO_DBG("called: ico_dbus_amb_get(objname=%s prop=%s zone=%d type=%d)",
205 itr->second->objname.c_str(),
206 itr->second->property.c_str(),
208 ms_dbusTypes[itr->second->type]);
209 int ret = ico_dbus_amb_get(itr->second->objname.c_str(),
210 itr->second->property.c_str(),
212 ms_dbusTypes[itr->second->type],
213 CicoSCVInfoManager::dbusAMBGetCB,
216 ICO_WRN("ico_dbus_amb_get failed. ret=%d", ret);
217 ICO_TRA("CicoSCVInfoManager::getVehicleInfo Leave(false)");
221 ICO_TRA("CicoSCVInfoManager::getVehicleInfo Leave(true)");
225 //==========================================================================
227 //==========================================================================
229 //--------------------------------------------------------------------------
231 * @brief start vehicle information monitoring
233 //--------------------------------------------------------------------------
235 CicoSCVInfoManager::startMonitoring(void)
237 ICO_TRA("CicoSCVInfoManager::startMonitoring Enter");
239 CicoSystemConfig* sysconf = CicoSystemConfig::getInstance();
240 CicoSCVehicleInfoConf* viconf = sysconf->getVehicleInfoConf();
241 std::map<int, CicoSCVIPropertyConf*>::iterator itr;
242 itr = viconf->properties.begin();
244 for (; itr != viconf->properties.end(); ++itr) {
245 ICO_DBG("called: ico_dbus_amb_find_property"
246 "(objname=%s prop=%s zone=%d type=%d)",
247 itr->second->objname.c_str(),
248 itr->second->property.c_str(),
250 ms_dbusTypes[itr->second->type]);
251 int ret = ico_dbus_amb_find_property(itr->second->objname.c_str(),
252 itr->second->property.c_str(),
254 ms_dbusTypes[itr->second->type],
255 CicoSCVInfoManager::dbusAMBFindCB,
258 ICO_WRN("ico_dbus_amb_find_property failed. ret=%d", ret);
262 ICO_TRA("CicoSCVInfoManager::startMonitoring Leave");
265 //--------------------------------------------------------------------------
267 * @brief stop vehicle information monitoring
269 //--------------------------------------------------------------------------
271 CicoSCVInfoManager::stopMonitoring(void)
273 ICO_TRA("CicoSCVInfoManager::stopMonitoring Enter");
275 CicoSystemConfig* sysconf = CicoSystemConfig::getInstance();
276 CicoSCVehicleInfoConf* viconf = sysconf->getVehicleInfoConf();
277 std::map<int, CicoSCVIPropertyConf*>::iterator itr;
278 itr = viconf->properties.begin();
279 for (; itr != viconf->properties.end(); ++itr) {
280 ICO_DBG("called: ico_dbus_amb_unsubscribe"
281 "(objname=%s prop=%s zone=%d type=%d)",
282 itr->second->objname.c_str(),
283 itr->second->property.c_str(),
285 ms_dbusTypes[itr->second->type]);
286 int ret = ico_dbus_amb_unsubscribe(itr->second->objname.c_str(),
287 itr->second->property.c_str(),
290 ICO_WRN("ico_dbus_amb_subscribe failed. ret=%d", ret);
294 ICO_TRA("CicoSCVInfoManager::stopMonitoring Leave");
297 //--------------------------------------------------------------------------
299 * @brief callback function of Ecore_End_Cb
301 * @param [in] user_data user data
302 * @param [in] func_data funnction data
304 //--------------------------------------------------------------------------
306 CicoSCVInfoManager::evVInfoFree(void* user_data, void* func_data)
308 ICO_TRA("CicoSCVInfoManager::evVInfoFree Enter");
309 delete static_cast<CicoSCVInfo*>(func_data);
310 ICO_TRA("CicoSCVInfoManager::evVInfoFree Leave");
313 //--------------------------------------------------------------------------
315 * @brief callback function of ecore timer
317 * @param [in] data user data
319 //--------------------------------------------------------------------------
321 CicoSCVInfoManager::ecoreRetryFindPropCB(void *data)
323 ICO_TRA("CicoSCVInfoManager::ecoreRetryFindPropCB Enter");
325 CicoSCVIPropertyConf* viProp = static_cast<CicoSCVIPropertyConf*>(data);
326 ICO_DBG("called: ico_dbus_amb_find_property"
327 "(objname=%s prop=%s zone=%d type=%d)",
328 viProp->objname.c_str(),
329 viProp->property.c_str(),
331 ms_dbusTypes[viProp->type]);
332 int ret = ico_dbus_amb_find_property(viProp->objname.c_str(),
333 viProp->property.c_str(),
335 ms_dbusTypes[viProp->type],
336 CicoSCVInfoManager::dbusAMBFindCB,
339 ICO_WRN("ico_dbus_amb_property failed. ret=%d", ret);
343 ICO_TRA("CicoSCVInfoManager::ecoreRetryFindPropCB Leave(cancel)");
344 return ECORE_CALLBACK_CANCEL;
347 //--------------------------------------------------------------------------
349 * @brief callback function of ico_dbus_amb_get result
351 * @param [in] objectname dbus object name
352 * @param [in] property vehicle information's name
353 * @param [in] type type of vechcle information
354 * @param [in] data user data
355 * @param [in] error error information
357 //--------------------------------------------------------------------------
359 CicoSCVInfoManager::dbusAMBFindCB(const char *objectname,
360 const char *property,
363 ico_dbus_error_t *error)
365 ICO_TRA("CicoSCVInfoManager::dbusAMBFindCB Enter"
366 "(objname=%s prop=%s type=%d)",
367 objectname, property, type);
370 ICO_WRN("data is null");
374 CicoSCVIPropertyConf* viProp = static_cast<CicoSCVIPropertyConf*>(data);
376 // if find property is error, retry.
378 CicoSystemConfig* sysconf = CicoSystemConfig::getInstance();
379 CicoSCVehicleInfoConf* viconf = sysconf->getVehicleInfoConf();
380 ICO_DBG("retryCnt=%d/%d", ms_retryCnt, viconf->retryCnt);
381 if (viconf->retryCnt > ms_retryCnt) {
383 ICO_DBG("called: ecore_timer_add");
384 Ecore_Timer *timer = NULL;
385 timer = ecore_timer_add((double)viconf->waitTime/1000.0f,
386 CicoSCVInfoManager::ecoreRetryFindPropCB,
389 ICO_ERR("ecore_timer_add() failed.");
393 ICO_TRA("CicoSCVInfoManager::dbusAMBFindCB Levae");
397 // get vehicle information
398 ICO_DBG("called: ico_dbus_amb_get(objname=%s prop=%s zone=%d type=%d)",
399 viProp->objname.c_str(),
400 viProp->property.c_str(),
402 ms_dbusTypes[viProp->type]);
403 int ret = ico_dbus_amb_get(viProp->objname.c_str(),
404 viProp->property.c_str(),
406 ms_dbusTypes[viProp->type],
407 CicoSCVInfoManager::dbusAMBGetCB,
410 ICO_WRN("ico_dbus_amb_subscribe failed. ret=%d", ret);
413 // subscribe vehicle information
414 ICO_DBG("called: ico_dbus_amb_subscribe"
415 "(objname=%s prop=%s zone=%d type=%d)",
416 viProp->objname.c_str(),
417 viProp->property.c_str(),
419 ms_dbusTypes[viProp->type]);
420 ret = ico_dbus_amb_subscribe(viProp->objname.c_str(),
421 viProp->property.c_str(),
423 ms_dbusTypes[viProp->type],
424 CicoSCVInfoManager::dbusAMBNotifyCB,
427 ICO_WRN("ico_dbus_amb_subscribe failed. ret=%d", ret);
430 ICO_TRA("CicoSCVInfoManager::dbusAMBFindCB Levae");
433 //--------------------------------------------------------------------------
435 * @brief callback function of ico_dbus_amb_get result
437 * @param [in] objectname dbus object name
438 * @param [in] property vehicle information's name
439 * @param [in] type type of vechcle information
440 * @param [in] value vechcle information's value
441 * @param [in] data user data
443 //--------------------------------------------------------------------------
445 CicoSCVInfoManager::dbusAMBGetCB(const char *objectname,
446 const char *property,
448 union dbus_value_variant value,
451 ICO_TRA("CicoSCVInfoManager::dbusAMBGetCB Enter"
452 "(objname=%s prop=%s type=%d)",
453 objectname, property, type);
456 ICO_WRN("data is null");
460 CicoSCVIPropertyConf* viConf = static_cast<CicoSCVIPropertyConf*>(data);
462 CicoSCVInfo* vinfo = new CicoSCVInfo(type, viConf->id, value);
463 ecore_event_add(ms_ecoreEvType, vinfo,
464 CicoSCVInfoManager::evVInfoFree, NULL);
466 ICO_TRA("CicoSCVInfoManager::dbusAMBGetCB Levae");
469 //--------------------------------------------------------------------------
471 * @brief callback function of ico_dbus_amb_get result
473 * @param [in] objectname dbus object name
474 * @param [in] property vehicle information's name
475 * @param [in] type type of vechcle information
476 * @param [in] value vechcle information's value
477 * @param [in] sequence number of sequence
478 * @parma [in] tv recored time
479 * @param [in] data user data
481 //--------------------------------------------------------------------------
483 CicoSCVInfoManager::dbusAMBNotifyCB(const char *objectname,
484 const char *property,
486 union dbus_value_variant value,
491 ICO_TRA("CicoSCVInfoManager::dbusAMBNotifyCB Enter"
492 "(objname=%s prop=%s type=%d)",
493 objectname, property, type);
496 ICO_WRN("data is null");
500 CicoSCVIPropertyConf* viConf = static_cast<CicoSCVIPropertyConf*>(data);
502 CicoSCVInfo* vinfo = new CicoSCVInfo(type, viConf->id, value);
503 ecore_event_add(ms_ecoreEvType, vinfo,
504 CicoSCVInfoManager::evVInfoFree, NULL);
506 ICO_TRA("CicoSCVInfoManager::dbusAMBNotifyCB Leave");
508 // vim:set expandtab ts=4 sw=4: