2 * Copyright 2007-2009 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
4 * All rights reserved. Distributed under the terms of the MIT License.
7 #include "LocalDeviceHandler.h"
10 LocalDeviceHandler::LocalDeviceHandler(HCIDelegate
* hd
)
13 fProperties
= new BMessage();
17 LocalDeviceHandler::~LocalDeviceHandler()
25 LocalDeviceHandler::GetID()
27 return fHCIDelegate
->Id();
32 LocalDeviceHandler::Launch(void)
34 return fHCIDelegate
->Launch();
39 LocalDeviceHandler::Available()
47 LocalDeviceHandler::Acquire(void)
54 LocalDeviceHandler::IsPropertyAvailable(const char* property
)
59 return (fProperties
->GetInfo(property
, &typeFound
, &countFound
) == B_OK
);
64 LocalDeviceHandler::AddWantedEvent(BMessage
* msg
)
67 // TODO: review why it is needed to replicate the msg
68 // printf("Adding request... %p\n", msg);
69 fEventsWanted
.AddMessage(msg
);
70 fEventsWanted
.Unlock();
75 LocalDeviceHandler::ClearWantedEvent(BMessage
* msg
)
78 fEventsWanted
.RemoveMessage(msg
);
79 fEventsWanted
.Unlock();
84 LocalDeviceHandler::ClearWantedEvent(BMessage
* msg
, uint16 event
, uint16 opcode
)
86 // Remove the whole petition from queue
94 while (msg
->FindInt16("eventExpected", eventIndex
, &eventFound
) == B_OK
) {
96 printf("%s:Event expected %d@%" B_PRId32
"...\n", __FUNCTION__
, event
,
99 if (eventFound
== event
) {
101 printf("%s:Event matches@%" B_PRId32
"\n", __FUNCTION__
, eventIndex
);
102 // there is an opcode specified
105 // The opcode matches
106 if ((msg
->FindInt16("opcodeExpected", eventIndex
, &opcodeFound
) == B_OK
)
107 && ((uint16
)opcodeFound
== opcode
)) {
109 // this should remove only the entry
110 printf("Removed event %#x and opcode %d from request %p\n",
112 (void)msg
->RemoveData("eventExpected", eventIndex
);
113 (void)msg
->RemoveData("opcodeExpected", eventIndex
);
118 // Event matches so far
119 printf("Removed event %d from message %p\n", event
, msg
);
120 (void)msg
->RemoveData("eventExpected", eventIndex
);
127 printf("%s:Nothing Found/Removed\n", __FUNCTION__
);
130 fEventsWanted
.Unlock();
136 LocalDeviceHandler::FindPetition(uint16 event
, uint16 opcode
, int32
* indexFound
)
143 fEventsWanted
.Lock();
145 for (int32 index
= 0 ; index
< fEventsWanted
.CountMessages() ; index
++) {
146 BMessage
* msg
= fEventsWanted
.FindMessage(index
);
147 // printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index,
148 // fEventsWanted.CountMessages(), msg);
149 // msg->PrintToStream();
153 while (msg
->FindInt16("eventExpected", eventIndex
, &eventFound
) == B_OK
) {
154 if (eventFound
== event
) {
156 // printf("%s:Event %d found@%ld...", __FUNCTION__, event, eventIndex);
157 // there is an opcode specified..
158 if (msg
->FindInt16("opcodeExpected", eventIndex
, &opcodeFound
)
161 if ((uint16
)opcodeFound
!= opcode
) {
162 // printf("%s:opcode does not match %d\n",
163 // __FUNCTION__, opcode);
167 // printf("Opcode matches %d\n", opcode);
169 // printf("No opcode specified\n");
172 fEventsWanted
.Unlock();
173 if (indexFound
!= NULL
)
174 *indexFound
= eventIndex
;
180 // printf("%s:Event %d not found\n", __FUNCTION__, event);
182 fEventsWanted
.Unlock();