dbg.h file is removed.
[profile/tv/apps/native/source.git] / src / mgr / usb.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <AppCommon.h>
18 #include "aul.h"
19 #include "usb.h"
20
21 #define FILE_BROWSER_APP "org.tizen.file-browser-tv-ref"
22 #define FILE_BROWSER_USB_KEY "source"
23 #define FILE_BROWSER_USB_VALUE "usb"
24
25 struct SUsb {
26         CUsb::SCallback conCb;
27 };
28
29
30 bool CUsb::Create(const SCallback *cb)
31 {
32         ASSERT(!m);
33
34         m = new SUsb;
35         if (!m) {
36                 _ERR("alloc failed");
37                 return false;
38         }
39
40         if (!CUsbListener::Create())
41                 _DBG("UsbListener creation failed");
42
43         m->conCb = *cb;
44
45         return true;
46 }
47
48 void CUsb::Destroy(void)
49 {
50         ASSERT(m);
51
52         if (CUsbListener::FlagCreate())
53                 CUsbListener::Destroy();
54
55         delete m;
56         m = NULL;
57 }
58
59 bool CUsb::SwitchTo(void)
60 {
61         bundle *b;
62         int err;
63
64         b = bundle_create();
65         if (!b)
66                 return false;
67
68         err = bundle_add(b, FILE_BROWSER_USB_KEY, FILE_BROWSER_USB_VALUE);
69         if (err) {
70                 _ERR("Add bundle value failed. err:%d", err);
71                 bundle_free(b);
72                 return false;
73         }
74
75         aul_launch_app(FILE_BROWSER_APP, b);
76         bundle_free(b);
77
78         return true;
79 }
80
81 void CUsb::GetConnected(void)
82 {
83         int count;
84         SUsbHostDeviceInfo devInfo;
85
86         if (!CUsbListener::FlagCreate())
87                 return;
88
89         count = ConnectionCount();
90         for (int i = 0; i < count; i++) {
91                 GetConnectedDevInfo(i, &devInfo);
92                 m->conCb.cb(m->conCb.cookie, USB_HOST_DEV_CONNECTED, &devInfo);
93         }
94 }
95
96 void CUsb::OnStatusChanged(SUsbHostDeviceInfo *changedDevice,
97                         SUsbHostDeviceStatus status)
98 {
99         m->conCb.cb(m->conCb.cookie, status, (void *)changedDevice);
100 }