TNB Library
TnbCeBluetoothAvrcpWatcher.h
[詳解]
1#pragma once
13#ifndef _WIN32_WCE
14 #error TnbCeBluetoothAvrcpWatcher.h is only supported on Windows CE platforms.
15#endif // _WIN32_WCE
16
17
18
20
21
22
23#ifndef _TnbDOXYGEN //Document作成用シンボル
24
25// bt_avrcp.h より
26#ifndef __BT_AVRCP_H__
27
28typedef struct _AvrcpMsg {
29 uint OpCode;
30 uint OpId;
31 uint Reserved[4];
32} AvrcpMsg;
33
34enum AVCOpCodes {
35 UnitInfo_t = 0x30,
36 SubunitInfo_t,
37 PassThru_t = 0x7C
38};
39
40enum PassThruOpId {
41 Select_t = 0x00,
42 Up_t,
43 Down_t,
44 Left_t,
45 Right_t,
46 RightUp_t,
47 RightDown_t,
48 LeftUp_t,
49 LeftDown_t,
50 RootMenu_t,
51 SetupMenu_t,
52 ContentsMenu_t,
53 FavMenu_t,
54 Exit_t,
55
56 ChannelUp_t = 0x30,
57 ChannelDown_t,
58 PrevChannel_t,
59 SoundSel_t,
60 InputSel_t,
61 DisplayInfo_t,
62 Help_t,
63 PageUp_t,
64 PageDown_t,
65
66 Power_t = 0x40,
67 VolUp_t,
68 VolDown_t,
69 Mute_t,
70 Play_t,
71 Stop_t,
72 Pause_t,
73 Record_t,
74 Rewind_t,
75 FastFwd_t,
76 Eject_t,
77 Forward_t,
78 Backward_t
79};
80#endif // __BT_AVRCP_H__
81
82#endif // _TnbDOXYGEN
83
84
85
86//TNB Library
87namespace TNB
88{
89
90
91
102{
103public:
104
114 {
116 virtual ~IListener(void) {}
117
124 virtual void OnBluetoothAvrcpEvent(DWORD code, DWORD id) = 0;
125 };
126
127
128 //--------------------------------------------
129
130
133 {
134 m_inner.pListener = NULL;
135 }
136
142 {
143 m_inner.pListener = P;
144 }
145
151 bool IsStarted(void) const
152 {
153 return m_inner.msgQueue.IsStarted();
154 }
155
161 bool Start(void)
162 {
163 LPCTSTR lpszAvrcpQueueName = _T("Avrcp10MsgQ");
164 Stop();
165 m_inner.msgQueue.SetListener(&m_inner);
166 MSGQUEUEOPTIONS opt = { 0 };
167 opt.dwFlags = MSGQUEUE_ALLOW_BROKEN;
168 opt.dwMaxMessages = 20;
169 opt.cbMaxMessage = 100;
170 opt.bReadAccess = TRUE;
171 if ( m_inner.msgQueue.Start(lpszAvrcpQueueName, opt, _T("AVRCP Watch")) )
172 {
173 return true;
174 }
175 DWORD r = ::GetLastError();
176 Stop();
177 ::SetLastError(r);
178 return false;
179 }
180
187 bool Stop(void)
188 {
189 return m_inner.msgQueue.Stop();
190 }
191
197 {
198 return m_inner.msgQueue.ReferThreadStatus();
199 }
200
207 static CStr ToString(DWORD code, DWORD id)
208 {
209 CStr s = _T("unknown");
210 if ( code == PassThru_t )
211 {
212 #ifndef _TnbDOXYGEN //Document作成用シンボル
213 #define _x_(SS) case SS##_t: s = _T(#SS); break;
214 switch ( id & 0x7F )
215 {
216 _x_(Select);
217 _x_(Up); _x_(Down); _x_(Left); _x_(Right);
218 _x_(RightUp); _x_(RightDown); _x_(LeftUp); _x_(LeftDown);
219 _x_(RootMenu); _x_(SetupMenu);
220 _x_(ContentsMenu);
221 _x_(FavMenu);
222 _x_(Exit);
223 _x_(ChannelUp); _x_(ChannelDown);
224 _x_(PrevChannel);
225 _x_(SoundSel); _x_(InputSel);
226 _x_(DisplayInfo);
227 _x_(Help);
228 _x_(PageUp); _x_(PageDown);
229 _x_(Power);
230 _x_(VolUp); _x_(VolDown); _x_(Mute);
231 _x_(Play); _x_(Stop); _x_(Pause); _x_(Record);
232 _x_(Rewind); _x_(FastFwd);
233 _x_(Eject);
234 _x_(Forward); _x_(Backward);
235 default:
236 break;
237 }
238 #undef _x_
239 #endif _TnbDOXYGEN
240 s += ((id & 0x80) == 0) ? _T(" Down") : _T(" Up");
241 }
242 return s;
243 }
244
245private:
247 class CInner : public CMsgQueueWatcherT<AvrcpMsg>::IListener
248 {
249 public:
256 virtual void OnMsgQueueWatcherEvent(const AvrcpMsg& data, size_t length, bool isAlert)
257 {
258 if ( pListener != NULL )
259 {
260 pListener->OnBluetoothAvrcpEvent(data.OpCode, data.OpId);
261 }
262// AvrcpMsg a = { 0 };
263// a.OpCode =
264// a.OpId = Stop_t;
265// msgQueue.Send(a);
266 }
269 };
270 CInner m_inner;
271};
272
273
274
275}; //TNB
276
277
278
279#if 0
280
281
282#define AVRCP_MSG_SZ TEXT("Avrcp10MsgQ")
283
284
285int AvrcpMsgProcess (void* p)
286{
287 static int avrcp_tick;
288 bool_t PlayState = 0;
289 bool_t bAvrcp = 0;
290 fraction Percent;
291 int Param = PLAYER_PLAY;
292 node* Player = Context()->Player;
293 MSGQUEUEOPTIONS mqOptions;
294 memset (&mqOptions, 0, sizeof(mqOptions));
295 mqOptions.dwFlags = MSGQUEUE_ALLOW_BROKEN;
296 mqOptions.dwSize = sizeof(mqOptions);
297 mqOptions.dwMaxMessages = 2;
298 mqOptions.cbMaxMessage = 100;
299 mqOptions.bReadAccess = TRUE;
300 hMsgQ = CreateMsgQueue(AVRCP_MSG_SZ, &mqOptions);
301 if (! hMsgQ)
302 {
303 goto exit_bt;
304 }
305 //_debug(L"MsgQueue created.");
306 while (hMsgQ != 0)
307 {
308 DWORD dwWait = WaitForSingleObject (hMsgQ, INFINITE);
309 NodeRegLoadValue(AVRCP_ID,AVRCP_ENABLE,&bAvrcp,sizeof(int),TYPE_INT);
310 if(! bAvrcp)
311 {
312 goto exit_bt;
313 }
314 if (WAIT_OBJECT_0 == dwWait)
315 {
316 AvrcpMsg btAvrcp;
317 DWORD dwFlags = 0;
318 DWORD dwBytesRead = 0;
319 BOOL fRet = ReadMsgQueue (hMsgQ, &btAvrcp, sizeof(AvrcpMsg), &dwBytesRead, 10, &dwFlags);
320 if (fRet)
321 {
322 if(hAvrcpConfMode==1)
323 {
324 avrcp_tick++;
325 if(avrcp_tick>1)
326 {
327 //_debug(L"Avrcp Config Accessed:%x,tick:%d",btAvrcp.OpId,avrcp_tick);
328 intConfAvrcpMsg=btAvrcp.OpId;
329 avrcp_tick=0;
330 }
331 }
332 else
333 {
334 //_debug(L"Avrcp Normal Accessed:%x",btAvrcp.OpId);
335 //0x44 & 0xC4 = Pause
336 //0x46 & 0xC6 = Play
337 //0x4B & 0xCB = Next
338 //0x4C & 0xCC = Prev
339 //Pass_thru = 0x7c
340 if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_PLAY))
341 {
342 Param=PLAYER_PLAY;
343 if(Player->Get(Player,Param,&PlayState,sizeof(PlayState))==ERR_NONE)
344 {
345 PlayState = !PlayState;
346 }
347 else
348 {
349 PlayState = 1 - PlayState;
350 }
351 Player->Set(Player,Param,&PlayState,sizeof(PlayState));
352 }
353 else if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_PAUSE))
354 {
355 Param=PLAYER_PLAY;
356 if(Player->Get(Player,Param,&PlayState,sizeof(PlayState))==ERR_NONE)
357 {
358 PlayState = !PlayState;
359 }
360 else
361 {
362 PlayState = 1 - PlayState;
363 }
364 Player->Set(Player,Param,&PlayState,sizeof(PlayState));
365 }
366 else if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_STOP))
367 {
368 Param=PLAYER_STOP;
369 Player->Set(Player,Param,NULL,1);
370 Percent.Num = 0;
371 Percent.Den = TRACKMAX;
372 Player->Set(Player,PLAYER_PERCENT,&Percent,sizeof(Percent));
373 }
374 else if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_PREV))
375 {
376 Param=PLAYER_PREV;
377 Player->Set(Player,Param,NULL,0);
378 }
379 else if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_NEXT))
380 {
381 Param=PLAYER_NEXT;
382 Player->Set(Player,Param,NULL,0);
383 }
384 else if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_BACKWARD))
385 {
386 Param=PLAYER_MOVEBACK;
387 Player->Set(Player,Param,NULL,0);
388 }
389 else if(btAvrcp.OpId==GetAvrcpCmd(AVRCP_FORWARD))
390 {
391 Param=PLAYER_MOVEFFWD;
392 Player->Set(Player,Param,NULL,0);
393 }
394 if(GetAvrcpCmd(AVRCP_OFFSCREEN))
395 {
396 if(GetAvrcpCmd(AVRCP_LOCK_KEYPAD)) keybd_event(0x85,0,0,0);
397 SetSystemPowerState( NULL, POWER_STATE_IDLE, POWER_FORCE);
398 }
399 }
400 //SendMessage(HWND_BROADCAST, WM_USER+1985, btAvrcp.OpId, btAvrcp.OpCode);
401 }
402 }
403 }
404exit_bt:
405 if (hMsgQ)
406 {
407 CloseMsgQueue(hMsgQ);
408 hMsgQ=NULL;
409 }
410 return 0;
411}
412
413#endif
CE 用メッセージキュー関係のヘッダ
CThreadStatus & ReferThreadStatus(void)
[参照] 監視スレッド状態参照.
void SetListener(IListener *P)
[設定] リスナー設定.
CBluetoothAvrcpWatcher(void)
コンストラクタ
bool IsStarted(void) const
[確認] 監視確認.
bool Start(void)
[設定] 監視スタート.
static CStr ToString(DWORD code, DWORD id)
[変換] 文字列化.
bool Stop(void)
[設定] 監視ストップ.
メッセージキュー監視 (CE専用).
スレッド状態管理クラス
Definition: TnbThread.h:128
TNB Library
Definition: TnbDoxyTitle.txt:2
Bluetooth(CE) AVRCP 監視のリスナー.
virtual void OnBluetoothAvrcpEvent(DWORD code, DWORD id)=0
[通知] イベント通知.