| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#include <gadget/gadgetConfig.h> |
|---|
| 28 |
#include <gadget/Util/Debug.h> |
|---|
| 29 |
|
|---|
| 30 |
#include <gadget/RemoteInputManager.h> |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
#include <gadget/Type/BaseTypeFactory.h> |
|---|
| 34 |
#include <gadget/VirtualDevice.h> |
|---|
| 35 |
#include <gadget/DeviceServer.h> |
|---|
| 36 |
#include <gadget/Type/DeviceFactory.h> |
|---|
| 37 |
#include <gadget/InputManager.h> |
|---|
| 38 |
|
|---|
| 39 |
#include <gadget/Node.h> |
|---|
| 40 |
#include <cluster/ClusterManager.h> |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
#include <cluster/Packets/PacketFactory.h> |
|---|
| 44 |
#include <cluster/Packets/ConnectionRequest.h> |
|---|
| 45 |
#include <cluster/Packets/DeviceRequest.h> |
|---|
| 46 |
#include <cluster/Packets/DeviceAck.h> |
|---|
| 47 |
#include <cluster/Packets/ApplicationDataRequest.h> |
|---|
| 48 |
#include <cluster/Packets/EndBlock.h> |
|---|
| 49 |
#include <cluster/Packets/DataPacket.h> |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
#include <jccl/RTRC/ConfigManager.h> |
|---|
| 53 |
#include <jccl/Config/ConfigElement.h> |
|---|
| 54 |
|
|---|
| 55 |
#include <map> |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
namespace gadget |
|---|
| 68 |
{ |
|---|
| 69 |
RemoteInputManager::RemoteInputManager(const vpr::GUID& guid) : mHandlerGUID(guid) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
RemoteInputManager::~RemoteInputManager() |
|---|
| 75 |
{ |
|---|
| 76 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator j = mVirtualDevices.begin(); j != mVirtualDevices.end(); j++ ) |
|---|
| 77 |
{ |
|---|
| 78 |
if ( (*j).second != NULL ) |
|---|
| 79 |
{ |
|---|
| 80 |
delete (*j).second; |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
for ( std::vector<DeviceServer*>::iterator j = mDeviceServers.begin(); j != mDeviceServers.end(); j++ ) |
|---|
| 84 |
{ |
|---|
| 85 |
if ( (*j) != NULL ) |
|---|
| 86 |
{ |
|---|
| 87 |
delete (*j); |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
void RemoteInputManager::recoverFromLostNode(Node* lost_node) |
|---|
| 93 |
{ |
|---|
| 94 |
removeVirtualDevicesOnHost(lost_node->getHostname()); |
|---|
| 95 |
removeDeviceClientsForHost(lost_node->getHostname()); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
void RemoteInputManager::handlePacket(cluster::Packet* packet, Node* node) |
|---|
| 106 |
{ |
|---|
| 107 |
|
|---|
| 108 |
if ( NULL != packet && NULL != node ) |
|---|
| 109 |
{ |
|---|
| 110 |
switch ( packet->getPacketType() ) |
|---|
| 111 |
{ |
|---|
| 112 |
case cluster::Header::RIM_DEVICE_REQ: |
|---|
| 113 |
{ |
|---|
| 114 |
cluster::DeviceRequest* temp_device_request = dynamic_cast<cluster::DeviceRequest*>(packet); |
|---|
| 115 |
vprASSERT(NULL != temp_device_request && "Dynamic cast failed!"); |
|---|
| 116 |
std::string device_name = temp_device_request->getDeviceName(); |
|---|
| 117 |
|
|---|
| 118 |
if ( jccl::ConfigManager::instance()->isPendingStale() ) |
|---|
| 119 |
{ |
|---|
| 120 |
gadget::Input* temp_input_device = gadget::InputManager::instance()->getDevice(device_name); |
|---|
| 121 |
if ( temp_input_device != NULL ) |
|---|
| 122 |
{ |
|---|
| 123 |
DeviceServer* temp_device_server = getDeviceServer(device_name); |
|---|
| 124 |
if ( NULL == temp_device_server ) |
|---|
| 125 |
{ |
|---|
| 126 |
addDeviceServer(device_name, temp_input_device); |
|---|
| 127 |
temp_device_server = getDeviceServer(device_name); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
temp_device_server->addClient(node); |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
std::string temp_string = temp_input_device->getInputTypeName(); |
|---|
| 134 |
vpr::GUID temp_guid = temp_device_server->getId(); |
|---|
| 135 |
cluster::DeviceAck* temp_ack = |
|---|
| 136 |
new cluster::DeviceAck(mHandlerGUID, temp_guid, |
|---|
| 137 |
device_name, temp_string, true); |
|---|
| 138 |
node->send(temp_ack); |
|---|
| 139 |
delete temp_ack; |
|---|
| 140 |
} |
|---|
| 141 |
else |
|---|
| 142 |
{ |
|---|
| 143 |
std::string temp_string = ""; |
|---|
| 144 |
vpr::GUID empty_id; |
|---|
| 145 |
cluster::DeviceAck* temp_ack = |
|---|
| 146 |
new cluster::DeviceAck(mHandlerGUID, empty_id, device_name, |
|---|
| 147 |
temp_string, false); |
|---|
| 148 |
node->send(temp_ack); |
|---|
| 149 |
delete temp_ack; |
|---|
| 150 |
} |
|---|
| 151 |
} |
|---|
| 152 |
else |
|---|
| 153 |
{ |
|---|
| 154 |
vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) |
|---|
| 155 |
<< clrOutBOLD(clrRED,"Pending List is not stale(Config Manager is still configuring the local system) ") |
|---|
| 156 |
<< clrOutBOLD(clrRED,"So we can not process this device request right now.") << std::endl << vprDEBUG_FLUSH; |
|---|
| 157 |
|
|---|
| 158 |
std::string temp_string = ""; |
|---|
| 159 |
vpr::GUID empty_id; |
|---|
| 160 |
cluster::DeviceAck* temp_ack = |
|---|
| 161 |
new cluster::DeviceAck(mHandlerGUID, empty_id, device_name, |
|---|
| 162 |
temp_string, false); |
|---|
| 163 |
node->send(temp_ack); |
|---|
| 164 |
delete temp_ack; |
|---|
| 165 |
} |
|---|
| 166 |
break; |
|---|
| 167 |
} |
|---|
| 168 |
case cluster::Header::RIM_DEVICE_ACK: |
|---|
| 169 |
{ |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
cluster::DeviceAck* temp_device_ack = dynamic_cast<cluster::DeviceAck*>(packet); |
|---|
| 176 |
vprASSERT(NULL != temp_device_ack && "Dynamic cast failed!"); |
|---|
| 177 |
std::string device_name = temp_device_ack->getDeviceName(); |
|---|
| 178 |
|
|---|
| 179 |
if ( temp_device_ack->getAck() ) |
|---|
| 180 |
{ |
|---|
| 181 |
removePendingDeviceRequest(device_name); |
|---|
| 182 |
|
|---|
| 183 |
if ( getVirtualDevice(device_name) != NULL ) |
|---|
| 184 |
{ |
|---|
| 185 |
vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) << clrOutBOLD(clrRED, "ERROR:") |
|---|
| 186 |
<< "Somehow we already have a virtual device named: " << device_name << std::endl << vprDEBUG_FLUSH; |
|---|
| 187 |
} |
|---|
| 188 |
else |
|---|
| 189 |
{ |
|---|
| 190 |
addVirtualDevice(temp_device_ack->getId(), device_name, |
|---|
| 191 |
temp_device_ack->getDeviceBaseType(), |
|---|
| 192 |
temp_device_ack->getHostname()); |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
gadget::InputManager::instance()->addRemoteDevice(getVirtualDevice(device_name), device_name); |
|---|
| 196 |
} |
|---|
| 197 |
} |
|---|
| 198 |
else |
|---|
| 199 |
{ |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
} |
|---|
| 204 |
break; |
|---|
| 205 |
} |
|---|
| 206 |
case cluster::Header::RIM_DATA_PACKET: |
|---|
| 207 |
{ |
|---|
| 208 |
cluster::DataPacket* temp_data_packet = dynamic_cast<cluster::DataPacket*>(packet); |
|---|
| 209 |
vprASSERT(NULL != temp_data_packet && "Dynamic cast failed!"); |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
gadget::Input* virtual_device = getVirtualDevice(temp_data_packet->getObjectId()); |
|---|
| 215 |
if ( virtual_device != NULL ) |
|---|
| 216 |
{ |
|---|
| 217 |
vpr::BufferObjectReader* temp_reader = new vpr::BufferObjectReader(temp_data_packet->getDeviceData()); |
|---|
| 218 |
|
|---|
| 219 |
temp_reader->setAttrib("rim.timestamp.delta", node->getDelta()); |
|---|
| 220 |
virtual_device->readObject(temp_reader); |
|---|
| 221 |
delete temp_reader; |
|---|
| 222 |
} |
|---|
| 223 |
break; |
|---|
| 224 |
} |
|---|
| 225 |
default: |
|---|
| 226 |
{ |
|---|
| 227 |
std::cout << "RIM DOES NOT HANDLE THIS PACKET TYPE" << packet->getPacketType() << std::endl; |
|---|
| 228 |
break; |
|---|
| 229 |
} |
|---|
| 230 |
} |
|---|
| 231 |
} |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
bool RemoteInputManager::addVirtualDevice(const vpr::GUID& device_id, |
|---|
| 236 |
const std::string& name, |
|---|
| 237 |
const std::string& device_base_type, |
|---|
| 238 |
const std::string& hostname) |
|---|
| 239 |
{ |
|---|
| 240 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 241 |
|
|---|
| 242 |
vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) |
|---|
| 243 |
<< clrOutBOLD(clrMAGENTA, "[RemoteInputManager]") |
|---|
| 244 |
<< "Creating Virtual Device: " << name << std::endl << vprDEBUG_FLUSH; |
|---|
| 245 |
|
|---|
| 246 |
gadget::Input* temp_input_device = gadget::BaseTypeFactory::instance()->loadNetDevice(device_base_type); |
|---|
| 247 |
VirtualDevice* temp_virtual_device = new VirtualDevice(name, device_id, device_base_type, hostname, temp_input_device); |
|---|
| 248 |
|
|---|
| 249 |
mVirtualDevices[device_id] = temp_virtual_device; |
|---|
| 250 |
|
|---|
| 251 |
return true; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
void RemoteInputManager::addVirtualDevice(VirtualDevice* device) |
|---|
| 255 |
{ |
|---|
| 256 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 257 |
|
|---|
| 258 |
mVirtualDevices[device->getId()] = device; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
gadget::Input* RemoteInputManager::getVirtualDevice(const vpr::GUID& device_id) |
|---|
| 262 |
{ |
|---|
| 263 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 264 |
|
|---|
| 265 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin(); |
|---|
| 266 |
i != mVirtualDevices.end() ; i++ ) |
|---|
| 267 |
{ |
|---|
| 268 |
if ( (*i).first == device_id ) |
|---|
| 269 |
{ |
|---|
| 270 |
return((*i).second->getDevice()); |
|---|
| 271 |
} |
|---|
| 272 |
} |
|---|
| 273 |
return NULL; |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
gadget::Input* RemoteInputManager::getVirtualDevice(const std::string& device_name) |
|---|
| 277 |
{ |
|---|
| 278 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 279 |
|
|---|
| 280 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin(); |
|---|
| 281 |
i != mVirtualDevices.end() ; i++ ) |
|---|
| 282 |
{ |
|---|
| 283 |
if ( (*i).second->getName() == device_name ) |
|---|
| 284 |
{ |
|---|
| 285 |
return((*i).second->getDevice()); |
|---|
| 286 |
} |
|---|
| 287 |
} |
|---|
| 288 |
return NULL; |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
bool RemoteInputManager:: |
|---|
| 292 |
removeVirtualDevicesOnHost(const std::string& host_name) |
|---|
| 293 |
{ |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 297 |
|
|---|
| 298 |
std::vector<std::string> devices_to_remove; |
|---|
| 299 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin(); |
|---|
| 300 |
i != mVirtualDevices.end() ; i++ ) |
|---|
| 301 |
{ |
|---|
| 302 |
if ( (*i).second->getRemoteHostname() == host_name ) |
|---|
| 303 |
{ |
|---|
| 304 |
devices_to_remove.push_back((*i).second->getName()); |
|---|
| 305 |
} |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
for ( std::vector<std::string>::iterator i = devices_to_remove.begin(); |
|---|
| 309 |
i != devices_to_remove.end();i++ ) |
|---|
| 310 |
{ |
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
createPendingConfigRemoveAndAdd(*i); |
|---|
| 315 |
} |
|---|
| 316 |
return true; |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
bool RemoteInputManager:: |
|---|
| 320 |
removeDeviceClientsForHost(const std::string& host_name) |
|---|
| 321 |
{ |
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 325 |
|
|---|
| 326 |
vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) |
|---|
| 327 |
<< clrOutBOLD(clrMAGENTA,"[RemoteInputManager]") |
|---|
| 328 |
<< " Removing client, " << host_name << " from all Device Servers.\n" |
|---|
| 329 |
<< vprDEBUG_FLUSH; |
|---|
| 330 |
|
|---|
| 331 |
for ( std::vector<DeviceServer*>::iterator i = mDeviceServers.begin(); |
|---|
| 332 |
i != mDeviceServers.end() ; i++ ) |
|---|
| 333 |
{ |
|---|
| 334 |
(*i)->removeClient(host_name); |
|---|
| 335 |
} |
|---|
| 336 |
return true; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
void RemoteInputManager::removeVirtualDevice(const vpr::GUID& device_id) |
|---|
| 340 |
{ |
|---|
| 341 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 342 |
|
|---|
| 343 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin(); |
|---|
| 344 |
i != mVirtualDevices.end() ; i++ ) |
|---|
| 345 |
{ |
|---|
| 346 |
if ( (*i).first == device_id ) |
|---|
| 347 |
{ |
|---|
| 348 |
|
|---|
| 349 |
gadget::InputManager::instance()->removeDevice((*i).second->getName()); |
|---|
| 350 |
delete (*i).second; |
|---|
| 351 |
mVirtualDevices.erase(i); |
|---|
| 352 |
return; |
|---|
| 353 |
} |
|---|
| 354 |
} |
|---|
| 355 |
} |
|---|
| 356 |
|
|---|
| 357 |
void RemoteInputManager::removeVirtualDevice(const std::string& device_name) |
|---|
| 358 |
{ |
|---|
| 359 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
gadget::InputManager::instance()->removeDevice(device_name); |
|---|
| 363 |
|
|---|
| 364 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator i = mVirtualDevices.begin(); |
|---|
| 365 |
i != mVirtualDevices.end() ; i++ ) |
|---|
| 366 |
{ |
|---|
| 367 |
if ( (*i).second->getName() == device_name ) |
|---|
| 368 |
{ |
|---|
| 369 |
(*i).second->debugDump(vprDBG_CONFIG_LVL); |
|---|
| 370 |
delete (*i).second; |
|---|
| 371 |
mVirtualDevices.erase(i); |
|---|
| 372 |
return; |
|---|
| 373 |
} |
|---|
| 374 |
} |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
void RemoteInputManager::debugDumpVirtualDevices(int debug_level) |
|---|
| 378 |
{ |
|---|
| 379 |
vpr::Guard<vpr::Mutex> guard(mVirtualDevicesLock); |
|---|
| 380 |
|
|---|
| 381 |
vpr::DebugOutputGuard dbg_output(gadgetDBG_RIM,debug_level, |
|---|
| 382 |
std::string("-------------- Virtual Devices --------------\n"), |
|---|
| 383 |
std::string("---------------------------------------------\n")); |
|---|
| 384 |
for ( std::map<vpr::GUID, VirtualDevice*>::iterator j = mVirtualDevices.begin(); j != mVirtualDevices.end(); j++ ) |
|---|
| 385 |
{ |
|---|
| 386 |
(*j).second->debugDump(debug_level); |
|---|
| 387 |
} |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
bool RemoteInputManager::addDeviceServer(const std::string& name, |
|---|
| 394 |
gadget::Input* device) |
|---|
| 395 |
{ |
|---|
| 396 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 397 |
|
|---|
| 398 |
DeviceServer* temp_device_server = |
|---|
| 399 |
new DeviceServer(name, device, mHandlerGUID); |
|---|
| 400 |
mDeviceServers.push_back(temp_device_server); |
|---|
| 401 |
|
|---|
| 402 |
return true; |
|---|
| 403 |
} |
|---|
| 404 |
|
|---|
| 405 |
void RemoteInputManager::addDeviceServer(DeviceServer* device) |
|---|
| 406 |
{ |
|---|
| 407 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 408 |
mDeviceServers.push_back(device); |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
DeviceServer* RemoteInputManager::getDeviceServer(const std::string& device_name) |
|---|
| 412 |
{ |
|---|
| 413 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 414 |
|
|---|
| 415 |
for ( std::vector<DeviceServer*>::iterator i = mDeviceServers.begin(); |
|---|
| 416 |
i != mDeviceServers.end() ; i++ ) |
|---|
| 417 |
{ |
|---|
| 418 |
if ( (*i)->getName() == device_name ) |
|---|
| 419 |
{ |
|---|
| 420 |
return(*i); |
|---|
| 421 |
} |
|---|
| 422 |
} |
|---|
| 423 |
return NULL; |
|---|
| 424 |
} |
|---|
| 425 |
|
|---|
| 426 |
void RemoteInputManager::removeDeviceServer(const std::string& device_name) |
|---|
| 427 |
{ |
|---|
| 428 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 429 |
|
|---|
| 430 |
for ( std::vector<DeviceServer*>::iterator i = mDeviceServers.begin(); |
|---|
| 431 |
i != mDeviceServers.end() ; i++ ) |
|---|
| 432 |
{ |
|---|
| 433 |
if ( (*i)->getName() == device_name ) |
|---|
| 434 |
{ |
|---|
| 435 |
delete (*i); |
|---|
| 436 |
mDeviceServers.erase(i); |
|---|
| 437 |
return; |
|---|
| 438 |
} |
|---|
| 439 |
} |
|---|
| 440 |
} |
|---|
| 441 |
|
|---|
| 442 |
void RemoteInputManager::debugDumpDeviceServers(int debug_level) |
|---|
| 443 |
{ |
|---|
| 444 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 445 |
|
|---|
| 446 |
vpr::DebugOutputGuard dbg_output(gadgetDBG_RIM,debug_level, |
|---|
| 447 |
std::string("-------------- Device Servers --------------\n"), |
|---|
| 448 |
std::string("---------------------------------------------\n")); |
|---|
| 449 |
for ( std::vector<DeviceServer*>::iterator j = mDeviceServers.begin(); j != mDeviceServers.end(); j++ ) |
|---|
| 450 |
{ |
|---|
| 451 |
(*j)->lockClients(); |
|---|
| 452 |
(*j)->debugDump(debug_level); |
|---|
| 453 |
(*j)->unlockClients(); |
|---|
| 454 |
} |
|---|
| 455 |
} |
|---|
| 456 |
|
|---|
| 457 |
void RemoteInputManager::sendDataAndSync() |
|---|
| 458 |
{ |
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
vpr::Guard<vpr::Mutex> guard(mDeviceServersLock); |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
for ( unsigned int i=0; i<mDeviceServers.size(); i++ ) |
|---|
| 468 |
{ |
|---|
| 469 |
mDeviceServers[i]->updateLocalData(); |
|---|
| 470 |
mDeviceServers[i]->send(); |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
} |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
vpr::Uint16 RemoteInputManager::getNumberPendingDeviceRequests() |
|---|
| 580 |
{ |
|---|
| 581 |
vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock); |
|---|
| 582 |
return(mPendingDeviceRequests.size()); |
|---|
| 583 |
} |
|---|
| 584 |
|
|---|
| 585 |
bool RemoteInputManager::createPendingConfigRemove(std::string device_name) |
|---|
| 586 |
{ |
|---|
| 587 |
jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance(); |
|---|
| 588 |
|
|---|
| 589 |
cfg_mgr->lockActive(); |
|---|
| 590 |
std::vector<jccl::ConfigElementPtr>::iterator active_begin = cfg_mgr->getActiveBegin(); |
|---|
| 591 |
std::vector<jccl::ConfigElementPtr>::iterator active_end = cfg_mgr->getActiveEnd(); |
|---|
| 592 |
std::vector<jccl::ConfigElementPtr>::iterator i; |
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
for ( i = active_begin ; i != active_end ; i++ ) |
|---|
| 596 |
{ |
|---|
| 597 |
if ( (*i)->getName() == device_name ) |
|---|
| 598 |
{ |
|---|
| 599 |
cfg_mgr->addConfigElement(*i, jccl::ConfigManager::PendingElement::REMOVE); |
|---|
| 600 |
|
|---|
| 601 |
cfg_mgr->unlockActive(); |
|---|
| 602 |
cfg_mgr->removeActive(device_name); |
|---|
| 603 |
cfg_mgr->lockActive(); |
|---|
| 604 |
} |
|---|
| 605 |
} |
|---|
| 606 |
cfg_mgr->unlockActive(); |
|---|
| 607 |
return true; |
|---|
| 608 |
} |
|---|
| 609 |
|
|---|
| 610 |
bool RemoteInputManager:: |
|---|
| 611 |
createPendingConfigRemoveAndAdd(std::string device_name) |
|---|
| 612 |
{ |
|---|
| 613 |
jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance(); |
|---|
| 614 |
|
|---|
| 615 |
cfg_mgr->lockActive(); |
|---|
| 616 |
std::vector<jccl::ConfigElementPtr>::iterator active_begin = cfg_mgr->getActiveBegin(); |
|---|
| 617 |
std::vector<jccl::ConfigElementPtr>::iterator active_end = cfg_mgr->getActiveEnd(); |
|---|
| 618 |
std::vector<jccl::ConfigElementPtr>::iterator i; |
|---|
| 619 |
for ( i = active_begin ; i != active_end ; i++ ) |
|---|
| 620 |
{ |
|---|
| 621 |
if ( (*i)->getName() == device_name ) |
|---|
| 622 |
{ |
|---|
| 623 |
cfg_mgr->addConfigElement(*i, jccl::ConfigManager::PendingElement::REMOVE); |
|---|
| 624 |
cfg_mgr->addConfigElement(*i, jccl::ConfigManager::PendingElement::ADD); |
|---|
| 625 |
|
|---|
| 626 |
cfg_mgr->unlockActive(); |
|---|
| 627 |
cfg_mgr->removeActive(device_name); |
|---|
| 628 |
cfg_mgr->lockActive(); |
|---|
| 629 |
} |
|---|
| 630 |
} |
|---|
| 631 |
cfg_mgr->unlockActive(); |
|---|
| 632 |
return true; |
|---|
| 633 |
} |
|---|
| 634 |
|
|---|
| 635 |
void RemoteInputManager::addPendingDeviceRequest(cluster::DeviceRequest* new_device_req, Node* node) |
|---|
| 636 |
{ |
|---|
| 637 |
vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock); |
|---|
| 638 |
mPendingDeviceRequests[new_device_req] = node; |
|---|
| 639 |
} |
|---|
| 640 |
|
|---|
| 641 |
void RemoteInputManager::removePendingDeviceRequest(std::string device_name) |
|---|
| 642 |
{ |
|---|
| 643 |
vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock); |
|---|
| 644 |
|
|---|
| 645 |
std::map<cluster::DeviceRequest*, Node*>::iterator begin = mPendingDeviceRequests.begin(); |
|---|
| 646 |
std::map<cluster::DeviceRequest*, Node*>::iterator end = mPendingDeviceRequests.end(); |
|---|
| 647 |
std::map<cluster::DeviceRequest*, Node*>::iterator i; |
|---|
| 648 |
|
|---|
| 649 |
for ( i = begin ; i != end ; i++ ) |
|---|
| 650 |
{ |
|---|
| 651 |
if ( (*i).first->getDeviceName() == device_name ) |
|---|
| 652 |
{ |
|---|
| 653 |
mPendingDeviceRequests.erase(i); |
|---|
| 654 |
return; |
|---|
| 655 |
} |
|---|
| 656 |
} |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
void RemoteInputManager::sendDeviceRequests() |
|---|
| 660 |
{ |
|---|
| 661 |
vpr::Guard<vpr::Mutex> guard(mPendingDeviceRequestsLock); |
|---|
| 662 |
|
|---|
| 663 |
std::map<cluster::DeviceRequest*, Node*>::iterator begin = mPendingDeviceRequests.begin(); |
|---|
| 664 |
std::map<cluster::DeviceRequest*, Node*>::iterator end = mPendingDeviceRequests.end(); |
|---|
| 665 |
std::map<cluster::DeviceRequest*, Node*>::iterator i; |
|---|
| 666 |
|
|---|
| 667 |
for ( i = begin ; i != end ; i++ ) |
|---|
| 668 |
{ |
|---|
| 669 |
if ( (*i).second->isConnected() ) |
|---|
| 670 |
{ |
|---|
| 671 |
vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) |
|---|
| 672 |
<< clrOutBOLD(clrMAGENTA, "[RemoteInputManager]") |
|---|
| 673 |
<< " Sending device request for: " << (*i).first->getDeviceName() |
|---|
| 674 |
<< std::endl << vprDEBUG_FLUSH; |
|---|
| 675 |
|
|---|
| 676 |
(*i).second->send((*i).first); |
|---|
| 677 |
} |
|---|
| 678 |
} |
|---|
| 679 |
} |
|---|
| 680 |
} |
|---|
| 681 |
|
|---|