33 #include "DeviceManager.h" 34 #include "objects/KinectDevice.h" 35 #include "ScolPlugin.h" 36 #include "lib/common.h" 38 template<>
DeviceManager* Singleton<DeviceManager>::instance = 0;
41 DeviceManager::DeviceManager()
45 DeviceManager::~DeviceManager()
63 void DeviceManager::close()
65 bool closeNI = (listOfKinectDevice.empty()) ?
false :
true;
66 for (KinectDeviceMap::iterator it = listOfKinectDevice.begin(); it != listOfKinectDevice.end(); it++)
68 SAFE_DELETE(it->second);
71 listOfKinectDevice.clear();
75 nite::NiTE::shutdown();
76 openni::OpenNI::shutdown();
80 unsigned int DeviceManager::createId()
83 while (listOfKinectDevice.find(idFound) != listOfKinectDevice.end())
93 if (listOfKinectDevice.empty())
96 if (openni::OpenNI::initialize() != openni::STATUS_OK)
98 MMechostr(MSKDEBUG,
" > OpenNI initialization failed ! : %s\n", openni::OpenNI::getExtendedError());
102 if (nite::NiTE::initialize() != nite::STATUS_OK)
104 MMechostr(MSKDEBUG,
" > NIte initialization failed ! : \n");
110 addKinectDevice(newKinectDevice);
111 return newKinectDevice;
114 void DeviceManager::DestroyKinectDevice(
KinectDevice* existingKinectDevice)
116 KinectDeviceMap::iterator iKinectDeviceSearched = listOfKinectDevice.find(existingKinectDevice->GetId());
117 if (iKinectDeviceSearched != listOfKinectDevice.end())
119 listOfKinectDevice.erase(iKinectDeviceSearched);
120 SAFE_DELETE(existingKinectDevice);
123 MMechostr(MSKRUNTIME,
"DeviceManagerManager::DestroyKinectDevice : Can't remove Kinect Device");
125 if (listOfKinectDevice.empty())
127 nite::NiTE::shutdown();
128 openni::OpenNI::shutdown();
132 void DeviceManager::addKinectDevice(
KinectDevice* existingKinectDevice)
134 KinectDeviceMap::iterator iKinectDeviceSearched = listOfKinectDevice.find(existingKinectDevice->GetId());
135 if (iKinectDeviceSearched == listOfKinectDevice.end())
137 listOfKinectDevice.insert(std::make_pair(existingKinectDevice->GetId(), existingKinectDevice));
140 MMechostr(MSKRUNTIME,
"DeviceManager::addKinectDevice : Kinect Device already Exists");
143 KinectDevice* DeviceManager::GetKinectDevice(
unsigned int id)
145 KinectDeviceMap::iterator iKinectDeviceSearched = listOfKinectDevice.find(
id);
146 if(iKinectDeviceSearched != listOfKinectDevice.end())
148 return iKinectDeviceSearched->second;
Kinect device handling. .
Handle DeviceManager type. .