From 91024efa122ea2db2f7dd52efd88389d80881c12 Mon Sep 17 00:00:00 2001 From: Jehun Lim Date: Thu, 9 Apr 2015 11:35:38 +0900 Subject: [PATCH] apply CUsbConnectionListener in application-common Change-Id: Ia7a4ee4a3d9a9f0101bb39fd2b09c05468b69da9 Signed-off-by: Jehun Lim --- CMakeLists.txt | 1 + include/mgr/SourceInfo.h | 30 +++++------ include/mgr/source_mgr.h | 6 +-- include/mgr/usb.h | 25 +++++----- src/mgr/SourceInfo.cpp | 71 ++++++++++---------------- src/mgr/source_mgr.cpp | 107 +++++++++++++++++++-------------------- src/mgr/usb.cpp | 118 +++++++++----------------------------------- src/util/util.cpp | 2 +- src/view/menu_view.cpp | 4 +- src/view/plugged_layout.cpp | 4 +- 10 files changed, 136 insertions(+), 232 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b90fed..4de68e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ ADD_EXECUTABLE(${PROJECT_NAME} src/util/util.cpp src/mgr/source_mgr.cpp src/mgr/SourceInfo.cpp + src/mgr/usb.cpp src/mgr/external.cpp src/view/allsource_view.cpp src/view/plugged_layout.cpp diff --git a/include/mgr/SourceInfo.h b/include/mgr/SourceInfo.h index d5d4734..f4b51f2 100644 --- a/include/mgr/SourceInfo.h +++ b/include/mgr/SourceInfo.h @@ -21,30 +21,30 @@ class CSourceInfo { private: - ext_type m_eConnType; - int m_nFlag; - char *m_pName; - char *m_pType; + int m_nId; + int m_nType; + char *m_pName; + char *m_pTypeName; void *m_pData; public: CSourceInfo(); - virtual ~CSourceInfo(); + virtual ~CSourceInfo() {}; - void SetFlag(int flag); - int Flag(void); + void SetId(int nId); + int Id(void); - void SetName(const char *name); - const char *Name(void); + void SetType(int nType); + int Type(void); - void SetType(const char *type); - const char *Type(void); + void SetName(const char *pName); + const char *Name(void); - void SetConnType(ext_type type); - ext_type ConnType(void); + void SetTypeName(const char *pTypeName); + const char *TypeName(void); - void SetData(void *pData); - void* Data(void); + void SetData(void *pData); + void *Data(void); const char *IconPath(void); diff --git a/include/mgr/source_mgr.h b/include/mgr/source_mgr.h index ab42253..c94ee6b 100644 --- a/include/mgr/source_mgr.h +++ b/include/mgr/source_mgr.h @@ -38,14 +38,14 @@ private: struct SSourceMgr *m; private: - static void sm_CbPlug(int is_plugged, void *data, void *dev); - void m_OnPlug(int is_plugged, void* dev); + static void sm_CbUsbPlug(void *cookie, int status, void *data); + void m_OnUsbPlug(int status, void *data); static void sm_CbExternalPlug(int is_plugged, void *cbdata, void *data); void m_OnExternalPlug(int is_plugged, void *data); CSourceInfo *m_AllocSI(int type); - CSourceInfo *m_AllocUsbSI(void *dev); + CSourceInfo *m_AllocUsbSI(void *data); protected: diff --git a/include/mgr/usb.h b/include/mgr/usb.h index 31b3718..9f32d75 100644 --- a/include/mgr/usb.h +++ b/include/mgr/usb.h @@ -14,36 +14,33 @@ * limitations under the License. */ -#if 0 #ifndef __USB_H__ #define __USB_H__ -#include "usb-device.h" - +class CUsb : public CUsbConnectionListener { +public: + struct SCallback { + void (*cb)(void *cookie, int status, void *data); + void *cookie; + }; -class CUsb { private: struct SUsb* m; -private: - - static void sm_CbConnected(usb_device_h dev, char *action, void *data); - public: CUsb() : m(0) {} virtual ~CUsb() {} - bool Create(void(*plug_cb)(int is_plugged, void *data, void *dev), void *data); + bool Create(const SCallback *cb); virtual void Destroy(void); - bool GetConnected(void); + static bool SwitchTo(void); + void GetConnected(void); - static bool SwitchTo(void); - static char* DeviceName(usb_device_h dev); - static int DeviceAddress(usb_device_h dev); + void OnStatusChanged(SUsbHostDeviceInfo *changedDevice, + SUsbHostDeviceStatus status); }; #endif /* __USB_H__ */ -#endif diff --git a/src/mgr/SourceInfo.cpp b/src/mgr/SourceInfo.cpp index a07a2bb..aa05382 100644 --- a/src/mgr/SourceInfo.cpp +++ b/src/mgr/SourceInfo.cpp @@ -20,11 +20,10 @@ #include "external.h" #include "AppCommon.h" +#include "UsbConnectionListener.h" #include "SourceInfo.h" #include "external.h" -#if 0 #include "usb.h" -#endif #define ICON_PATH_USB IMAGEDIR"/ico_usb.png" @@ -41,77 +40,61 @@ CSourceInfo::CSourceInfo() { - m_eConnType = CONN_TYPE_TV; - m_nFlag = 0; + m_nId = 0; + m_nType = CONN_TYPE_TV; m_pName = NULL; - m_pType = NULL; + m_pTypeName = NULL; m_pData = NULL; } - -CSourceInfo::~CSourceInfo() +void CSourceInfo::SetId(int nId) { - delete[] m_pName; - delete[] m_pType; + m_nId = nId; } - -void CSourceInfo::SetFlag(int flag) +int CSourceInfo::Id(void) { - m_nFlag = flag; + return m_nId; } - -int CSourceInfo::Flag(void) +void CSourceInfo::SetType(int nType) { - return m_nFlag; + m_nType = nType; } +int CSourceInfo::Type(void) +{ + return m_nType; +} -void CSourceInfo::SetName(const char *name) +void CSourceInfo::SetName(const char *pName) { delete[] m_pName; - m_pName = new char[strlen(name) + 1]; + m_pName = new char[strlen(pName) + 1]; if (!m_pName) return; - strcpy(m_pName, name); + strcpy(m_pName, pName); } - const char *CSourceInfo::Name(void) { return m_pName; } - -void CSourceInfo::SetType(const char *type) +void CSourceInfo::SetTypeName(const char *pTypeName) { - delete[] m_pType; - m_pType = new char[strlen(type) + 1]; - if (!m_pType) + delete[] m_pTypeName; + m_pTypeName = new char[strlen(pTypeName) + 1]; + if (!m_pTypeName) return; - strcpy(m_pType, type); -} - - -const char *CSourceInfo::Type(void) -{ - return m_pType; + strcpy(m_pTypeName, pTypeName); } - -void CSourceInfo::SetConnType(ext_type type) +const char *CSourceInfo::TypeName(void) { - m_eConnType = type; + return m_pTypeName; } - -ext_type CSourceInfo::ConnType(void) -{ - return m_eConnType; -} - - void CSourceInfo::SetData(void *pData) { m_pData = pData; @@ -126,7 +109,7 @@ void* CSourceInfo::Data(void) const char *CSourceInfo::IconPath(void) { - switch (m_eConnType) { + switch (m_nType) { case CONN_TYPE_USB: return ICON_PATH_USB; case CONN_TYPE_TV: @@ -164,11 +147,9 @@ const char *CSourceInfo::IconPath(void) bool CSourceInfo::SwitchTo(void) { - switch (m_eConnType) { -#if 0 + switch (m_nType) { case CONN_TYPE_USB: return CUsb::SwitchTo(); -#endif case CONN_TYPE_TV: return CExternal::SwitchTo(CONN_TYPE_TV); default: diff --git a/src/mgr/source_mgr.cpp b/src/mgr/source_mgr.cpp index 1020182..911f7cd 100644 --- a/src/mgr/source_mgr.cpp +++ b/src/mgr/source_mgr.cpp @@ -19,14 +19,13 @@ #include #include "AppCommon.h" +#include "UsbConnectionListener.h" #include "external.h" #include "source_mgr.h" #include "dbg.h" #include "aul.h" #include "util.h" -#if 0 #include "usb.h" -#endif #define DEFAULT_USB_NAME "USB Dev" #define DEFAULT_EXT_NAME "External" @@ -47,9 +46,7 @@ struct SSourceMgr { void *data; } cb; -#if 0 - CUsb u; -#endif + CUsb *usb; CExternal ext; SSourceMgr() { @@ -68,7 +65,7 @@ void CSourceMgr::t_FreeAllSource(void) EINA_LIST_FREE(m->plugged_list, obj) { si = (CSourceInfo *)obj; - switch (si->ConnType()) { + switch (si->Type()) { case CONN_TYPE_USB: t_Free(si); break; @@ -94,52 +91,48 @@ void CSourceMgr::t_UpdateUI(void *data, enum update_ui update_type) m->cb.cbUpdateSourceList(m->cb.data, data, update_type); } -#if 0 -CSourceInfo *CSourceMgr::m_AllocUsbSI(void *dev) +CSourceInfo *CSourceMgr::m_AllocUsbSI(void *data) { + CUsbConnectionListener::SUsbHostDeviceInfo *devInfo; CSourceInfo *si; const char *name; - if (!dev) { - _ERR("Invalid argument"); - return NULL; - } + devInfo = (CUsbConnectionListener::SUsbHostDeviceInfo *)data; - si = (CSourceInfo *)calloc(1, sizeof(*si)); + si = new CSourceInfo; if (!si) { - _ERR("calloc failed"); + _ERR("alloc failed"); return NULL; } - name = CUsb::DeviceName((usb_device_h)dev); + si->SetId(devInfo->vendorId); + si->SetType(CONN_TYPE_USB); + name = devInfo->product; si->SetName(name ? name : DEFAULT_USB_NAME); - si->SetType(USB_CONN_TYPE); - si->SetConnType(CONN_TYPE_USB); - si->SetFlag(CUsb::DeviceAddress((usb_device_h)dev)); + si->SetTypeName(USB_CONN_TYPE); return si; } - -void CSourceMgr::sm_CbPlug(int is_plugged, void *data, void *dev) +void CSourceMgr::sm_CbUsbPlug(void *cookie, int status, void *data) { - CSourceMgr* root = (CSourceMgr*)data; + CSourceMgr *root = (CSourceMgr *)cookie; + if (root) - root->m_OnPlug(is_plugged, dev); + root->m_OnUsbPlug(status, data); } - -void CSourceMgr::m_OnPlug(int is_plugged, void *dev) +void CSourceMgr::m_OnUsbPlug(int status, void *data) { + CUsbConnectionListener::SUsbHostDeviceInfo *devInfo; CSourceInfo *si; void *obj; Eina_List *list, *list_next; - if (!dev) - return; + devInfo = (CUsbConnectionListener::SUsbHostDeviceInfo *)data; - if (is_plugged) { - si = m_AllocUsbSI(dev); + if (status == CUsbConnectionListener::USB_HOST_DEV_CONNECTED) { + si = m_AllocUsbSI(devInfo); if (!si) return; @@ -148,8 +141,8 @@ void CSourceMgr::m_OnPlug(int is_plugged, void *dev) } else { EINA_LIST_FOREACH_SAFE(m->plugged_list, list, list_next, obj) { si = (CSourceInfo *)obj; - if (si->ConnType() == CONN_TYPE_USB && - si->Flag() == CUsb::DeviceAddress((usb_device_h)dev)) { + if (si->Type() == CONN_TYPE_USB && + si->Id() == devInfo->vendorId) { m->plugged_list = eina_list_remove( m->plugged_list, si); @@ -160,7 +153,6 @@ void CSourceMgr::m_OnPlug(int is_plugged, void *dev) } } } -#endif void CSourceMgr::sm_CbExternalPlug(int is_plugged, void *cbdata, void *data) { @@ -190,7 +182,7 @@ void CSourceMgr::m_OnExternalPlug(int is_plugged, void *data) else { EINA_LIST_FOREACH_SAFE(m->plugged_list, list, list_next, obj) { si = (CSourceInfo *)obj; - if (si->ConnType() == *ext_type) { + if (si->Type() == *ext_type) { m->plugged_list = eina_list_remove( m->plugged_list, si); @@ -217,9 +209,9 @@ CSourceInfo *CSourceMgr::m_AllocSI(int type) name = CExternal::Name((ext_type)type); si->SetName(name ? name : DEFAULT_EXT_NAME); if (type == CONN_TYPE_TV) - si->SetType(TV_CONN_TYPE); + si->SetTypeName(TV_CONN_TYPE); - si->SetConnType((ext_type)type); + si->SetType((ext_type)type); return si; } @@ -229,39 +221,47 @@ bool CSourceMgr::t_Create(TUpdateUI cb, void *data) { ASSERT(!m); - CExternal::SCallback scb; + CUsb::SCallback usbCb; + CExternal::SCallback extCb; m = new SSourceMgr; if (!m) { _ERR("Create src_mgr failed."); - return NULL; + return false; } -#if 0 - if (!m->u.Create(sm_CbPlug, this)) { - _ERR("Initial storage source connection callback failed."); + m->usb = new CUsb; + if (!m->usb) { + _ERR("Create usb failed."); + return false; + } + + usbCb.cb = sm_CbUsbPlug; + usbCb.cookie = this; + + if (!m->usb->Create(&usbCb)) { + _ERR("Init usb failed."); delete m; m = NULL; return false; } -#endif - - m->cb.cbUpdateSourceList = cb; - m->cb.data = data; - scb.proc_cb = sm_CbExternalPlug; - scb.cbdata = m; + extCb.proc_cb = sm_CbExternalPlug; + extCb.cbdata = m; - if (!m->ext.Create(&scb)) { + if (!m->ext.Create(&extCb)) { _ERR("Init external failed."); -#if 0 - m->u.Destroy(); -#endif + + m->usb->Destroy(); + delete m; m = NULL; return false; } + m->cb.cbUpdateSourceList = cb; + m->cb.data = data; + return true; } @@ -271,9 +271,8 @@ void CSourceMgr::t_Destroy(void) ASSERT(m); t_FreeAllSource(); -#if 0 - m->u.Destroy(); -#endif + + m->usb->Destroy(); m->ext.Destroy(); delete m; @@ -320,9 +319,7 @@ void CSourceMgr::Refresh(void) t_FreeAllSource(); t_UpdateUI(NULL, SRC_UPDATE_ALL); -#if 0 - m->u.GetConnected(); -#endif + m->usb->GetConnected(); m->ext.GetConnected(); } diff --git a/src/mgr/usb.cpp b/src/mgr/usb.cpp index 8b54e12..88144f9 100644 --- a/src/mgr/usb.cpp +++ b/src/mgr/usb.cpp @@ -19,7 +19,7 @@ #include #include "AppCommon.h" -#include "usb-device.h" +#include "UsbConnectionListener.h" #include "dbg.h" #include "aul.h" #include "usb.h" @@ -29,113 +29,39 @@ #define FILE_BROWSER_USB_VALUE "usb" struct SUsb { - void (*plug_cb)(int is_plugged, void *data, void* dev); - void *cbdata; + CUsb::SCallback conCb; }; -void CUsb::sm_CbConnected(usb_device_h dev, char *action, void *data) -{ - SUsb* m = (SUsb*)data; - int is_plugged; - - if (!m) { - _ERR("Invalid argument"); - return; - } - - if (!strcmp(action, "added")) - is_plugged = 1; - else if (!strcmp(action, "removed")) - is_plugged = 0; - else - return; - - if (m->plug_cb) - m->plug_cb(is_plugged, m->cbdata, dev); -} - - -bool CUsb::Create(void (*plug_cb)(int is_plugged, void *data, void* dev), void *data) +bool CUsb::Create(const SCallback *cb) { ASSERT(!m); m = new SUsb; if (!m) { - _ERR("calloc failed"); + _ERR("alloc failed"); return false; } - int r = usb_device_init(); - if (r != 0) { - _ERR("SUsb device init failed"); - delete m; - m = NULL; - return false; - } + if (!CUsbConnectionListener::Create()) + _DBG("UsbConnectionListener creation failed"); - usb_set_connected_cb(sm_CbConnected, m); - - m->plug_cb = plug_cb; - m->cbdata = data; + m->conCb = *cb; return true; } - void CUsb::Destroy(void) { ASSERT(m); - usb_device_fini(); + if (CUsbConnectionListener::FlagCreate()) + CUsbConnectionListener::Destroy(); + delete m; m = NULL; } - -bool CUsb::GetConnected(void) -{ - ASSERT(m); - - usb_device_h dev; - usb_device_list_h dev_list; - int is_plugged; - int err; - - is_plugged = 1; - - err = usb_get_connected_device_number(USB_MASS_STORAGE); - if (err <= 0) { - _INFO("No mass storage device connected currently."); - return false; - } - - err = usb_device_get_device_list(USB_MASS_STORAGE, &dev_list); - if (err != 0) { - _ERR("get mass storage device failed;err=%d", err); - return false; - } - - err = usb_device_list_get_first(dev_list, &dev); - if (err != 0) { - _ERR("get 1th mass storage device failed;err=%d", err); - return false; - } - - do { - if (m->plug_cb) - m->plug_cb(is_plugged, m->cbdata, dev); - free_usb_device_h(dev); - err = usb_device_list_get_next(dev_list, &dev); - } while (!err); - - /*free usb_device_list*/ - usb_device_free_device_list(dev_list); - - return true; -} - - bool CUsb::SwitchTo(void) { bundle *b; @@ -158,20 +84,22 @@ bool CUsb::SwitchTo(void) return true; } - -char *CUsb::DeviceName(usb_device_h dev) +void CUsb::GetConnected(void) { - if (!dev) - return NULL; + int count; + SUsbHostDeviceInfo devInfo; - return usb_device_get_partlabel(dev); + count = ConnectionCount(); + for (int i = 0; i < count; i++) { + GetConnectedDevInfo(i, &devInfo); + m->conCb.cb(m->conCb.cookie, USB_HOST_DEV_CONNECTED, &devInfo); + } } - -int CUsb::DeviceAddress(usb_device_h dev) +void CUsb::OnStatusChanged(SUsbHostDeviceInfo *changedDevice, + SUsbHostDeviceStatus status) { - if (!dev) - return -1; - - return usb_device_get_address(dev); + m->conCb.cb(m->conCb.cookie, status, (void *)changedDevice); } + + diff --git a/src/util/util.cpp b/src/util/util.cpp index 6670b7c..20e4d5d 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -145,7 +145,7 @@ static char *_util_grid_text_get(void *data, Evas_Object *obj, const char *part) cret = si->Name(); ret = strdup(cret ? cret : NO_NAME); } else if (!strcmp(part, PART_ITEM_TYPE)) { - cret = si->Type(); + cret = si->TypeName(); ret = strdup(cret ? cret : NO_TYPE); } diff --git a/src/view/menu_view.cpp b/src/view/menu_view.cpp index 69d0fe6..a70c683 100644 --- a/src/view/menu_view.cpp +++ b/src/view/menu_view.cpp @@ -193,7 +193,7 @@ bool CMenuView::m_AddExternalMenuBtn(void) bool CMenuView::m_AddMenuBtn(void) { - switch (m->node->ConnType()) { + switch (m->node->Type()) { case CONN_TYPE_USB: return m_AddUsbMenuBtn(); case CONN_TYPE_TV: @@ -215,7 +215,7 @@ bool CMenuView::m_AddFocusItem(void) _(m->node->Name())); elm_object_part_text_set(m->base, PART_FOCUS_ITEM_TEXT_TYPE, - _(m->node->Type())); + _(m->node->TypeName())); path = m->node->IconPath(); if (!path) diff --git a/src/view/plugged_layout.cpp b/src/view/plugged_layout.cpp index d5d2b60..27777f4 100644 --- a/src/view/plugged_layout.cpp +++ b/src/view/plugged_layout.cpp @@ -196,7 +196,7 @@ void CPluggedLayout::m_TimerDelItem(void) return; prev = elm_gengrid_item_prev_get(m->del_it); - next = elm_gengrid_item_prev_get(m->del_it); + next = elm_gengrid_item_next_get(m->del_it); elm_object_item_data_set(m->del_it, NULL); elm_object_item_del(m->del_it); @@ -242,7 +242,7 @@ void CPluggedLayout::Update(void *data, enum update_ui type) m->del_it = (Elm_Object_Item*)si_data->Data(); si_data->SetData(NULL); - timer = ecore_timer_add(DEL_IT_TIME, sm_CbTimerDelItem, m); + timer = ecore_timer_add(DEL_IT_TIME, sm_CbTimerDelItem, this); elm_object_item_data_set(m->del_it, timer); util_dim_item(m->del_it); } else if (type == SRC_UPDATE_ALL) { -- 2.7.4