MCPcopy Create free account
hub / github.com/OpenKinect/libfreenect2 / close

Method close

src/libfreenect2.cpp:1030–1089  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1028}
1029
1030bool Freenect2DeviceImpl::close()
1031{
1032 LOG_INFO << "closing...";
1033
1034 if(state_ == Closed)
1035 {
1036 LOG_INFO << "already closed, doing nothing";
1037 return true;
1038 }
1039
1040 if(state_ == Streaming)
1041 {
1042 stop();
1043 }
1044
1045 CommandTransaction::Result result;
1046 command_tx_.execute(SetModeEnabledWith0x00640064Command(nextCommandSeq()), result);
1047 command_tx_.execute(SetModeDisabledCommand(nextCommandSeq()), result);
1048 /* This command actually reboots the device and makes it disappear for 3 seconds.
1049 * Protonect can restart instantly without it.
1050 */
1051#ifdef __APPLE__
1052 /* Kinect will disappear on Mac OS X regardless during close().
1053 * Painstaking effort could not determine the root cause.
1054 * See https://github.com/OpenKinect/libfreenect2/issues/539
1055 *
1056 * Shut down Kinect explicitly on Mac and wait a fixed time.
1057 */
1058 command_tx_.execute(ShutdownCommand(nextCommandSeq()), result);
1059 libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(4*1000));
1060#endif
1061
1062 if(pipeline_->getRgbPacketProcessor() != 0)
1063 pipeline_->getRgbPacketProcessor()->setFrameListener(0);
1064
1065 if(pipeline_->getDepthPacketProcessor() != 0)
1066 pipeline_->getDepthPacketProcessor()->setFrameListener(0);
1067
1068 if(has_usb_interfaces_)
1069 {
1070 LOG_INFO << "releasing usb interfaces...";
1071
1072 usb_control_.releaseInterfaces();
1073 has_usb_interfaces_ = false;
1074 }
1075
1076 LOG_INFO << "deallocating usb transfer pools...";
1077 rgb_transfer_pool_.deallocate();
1078 ir_transfer_pool_.deallocate();
1079
1080 LOG_INFO << "closing usb device...";
1081
1082 libusb_close(usb_device_handle_);
1083 usb_device_handle_ = 0;
1084 usb_device_ = 0;
1085
1086 state_ = Closed;
1087 LOG_INFO << "closed";

Callers 3

mainFunction · 0.45
endFunction · 0.45
mainFunction · 0.45

Calls 7

sleep_forFunction · 0.85
getRgbPacketProcessorMethod · 0.80
releaseInterfacesMethod · 0.80
executeMethod · 0.45
setFrameListenerMethod · 0.45
deallocateMethod · 0.45

Tested by

no test coverage detected