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
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);
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:
* 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
#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"
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;
const char *CSourceInfo::IconPath(void)
{
- switch (m_eConnType) {
+ switch (m_nType) {
case CONN_TYPE_USB:
return ICON_PATH_USB;
case CONN_TYPE_TV:
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:
#include <Ecore.h>
#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"
void *data;
} cb;
-#if 0
- CUsb u;
-#endif
+ CUsb *usb;
CExternal ext;
SSourceMgr() {
EINA_LIST_FREE(m->plugged_list, obj) {
si = (CSourceInfo *)obj;
- switch (si->ConnType()) {
+ switch (si->Type()) {
case CONN_TYPE_USB:
t_Free(si);
break;
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;
} 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);
}
}
}
-#endif
void CSourceMgr::sm_CbExternalPlug(int is_plugged, void *cbdata, 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);
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;
}
{
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;
}
ASSERT(m);
t_FreeAllSource();
-#if 0
- m->u.Destroy();
-#endif
+
+ m->usb->Destroy();
m->ext.Destroy();
delete m;
t_FreeAllSource();
t_UpdateUI(NULL, SRC_UPDATE_ALL);
-#if 0
- m->u.GetConnected();
-#endif
+ m->usb->GetConnected();
m->ext.GetConnected();
}
#include <Ecore.h>
#include "AppCommon.h"
-#include "usb-device.h"
+#include "UsbConnectionListener.h"
#include "dbg.h"
#include "aul.h"
#include "usb.h"
#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;
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);
}
+
+
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);
}
bool CMenuView::m_AddMenuBtn(void)
{
- switch (m->node->ConnType()) {
+ switch (m->node->Type()) {
case CONN_TYPE_USB:
return m_AddUsbMenuBtn();
case CONN_TYPE_TV:
_(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)
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);
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) {