| 467 | } |
| 468 | |
| 469 | oni::driver::DeviceBase* deviceOpen(const char* c_uri, const char* c_mode = NULL) |
| 470 | { |
| 471 | std::string uri(c_uri); |
| 472 | std::string mode(c_mode ? c_mode : ""); |
| 473 | if (uri.find("?") != std::string::npos) { |
| 474 | mode += "&"; |
| 475 | mode += uri.substr(uri.find("?") + 1); |
| 476 | uri = uri.substr(0, uri.find("?")); |
| 477 | } |
| 478 | std::stringstream ss(mode); |
| 479 | std::string buf; |
| 480 | while(std::getline(ss, buf, '&')) { |
| 481 | if (buf.find("=") != std::string::npos) { |
| 482 | config[buf.substr(0, buf.find("="))] = buf.substr(buf.find("=")+1); |
| 483 | } else { |
| 484 | if (0 < buf.length()) |
| 485 | config[buf] = ""; |
| 486 | } |
| 487 | } |
| 488 | WriteMessage("deiveOpen: " + uri); |
| 489 | for (std::map<std::string, std::string>::iterator it = config.begin(); it != config.end(); it++) { |
| 490 | WriteMessage(" " + it->first + " = " + it->second); |
| 491 | } |
| 492 | |
| 493 | for (OniDeviceMap::iterator iter = devices.begin(); iter != devices.end(); iter++) |
| 494 | { |
| 495 | std::string iter_uri(iter->first.uri); |
| 496 | if (iter_uri.substr(0, iter_uri.find("?")) == uri) // found |
| 497 | { |
| 498 | if (iter->second) // already open |
| 499 | { |
| 500 | return iter->second; |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | WriteMessage("Opening device " + std::string(uri)); |
| 505 | int id = uri_to_devid(iter->first.uri); |
| 506 | DeviceImpl* device = new DeviceImpl(id); |
| 507 | // The LIBFREENECT2_PIPELINE variable allows to select |
| 508 | // the non-default pipeline |
| 509 | device->setFreenect2Device(freenect2.openDevice(id)); |
| 510 | device->setConfigStrings(config); |
| 511 | iter->second = device; |
| 512 | return device; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | LogError("Could not find device " + std::string(uri)); |
| 518 | return NULL; |
| 519 | } |
| 520 | |
| 521 | void deviceClose(oni::driver::DeviceBase* pDevice) |
| 522 | { |
nothing calls this directly
no test coverage detected