Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkToFDeviceFactoryManager.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
18 
19 //Microservices
20 #include <usGetModuleContext.h>
21 
22 
23 namespace mitk
24 {
26  {
27  ModuleContext* context = GetModuleContext();
29  if (m_RegisteredFactoryRefs.empty())
30  {
31  MITK_ERROR << "No factories registered!";
32  }
33  }
34 
36  {
37  }
38 
40  {
41  ModuleContext* context = GetModuleContext();
42  // std::string filter("(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.IToFDeviceFactory)");
43  // std::list<ServiceReference> serviceRef = context->GetServiceReference<IToFDeviceFactory>(/*filter*/);
44  std::vector<us::ServiceReference<IToFDeviceFactory> > serviceRefs = context->GetServiceReferences<IToFDeviceFactory>(/*filter*/);
45  if (!serviceRefs.empty())
46  {
47  for(std::vector<us::ServiceReference<IToFDeviceFactory> >::iterator it = serviceRefs.begin(); it != serviceRefs.end(); ++it)
48  {
49  IToFDeviceFactory* service = context->GetService( *it );
50  if(service)
51  {
52  m_RegisteredFactoryNames.push_back(std::string(service->GetFactoryName()));
53  }
54  }
55  }
57  }
58 
60  {
61  us::ModuleContext* context = us::GetModuleContext();
62  std::vector<std::string> result;
63  std::vector<us::ServiceReference<ToFCameraDevice> > serviceRefs = context->GetServiceReferences<ToFCameraDevice>();
64  if (!serviceRefs.empty())
65  {
66  for(std::empty<us::ServiceReference<ToFCameraDevice> >::iterator it = serviceRefs.begin(); it != serviceRefs.end(); ++it)
67  {
68  ToFCameraDevice* service = context->GetService( *it );
69  if(service)
70  {
71  result.push_back(std::string(service->GetNameOfClass()));
72  }
73  }
74  }
75  if(result.size() == 0)
76  {
77  MITK_ERROR << "No devices connected!";
78  }
79  return result;
80  }
81 
83  {
84  us::ModuleContext* context = us::GetModuleContext();
85 
86  std::vector<us::ServiceReference<IToFDeviceFactory> > serviceRefs = context->GetServiceReferences<IToFDeviceFactory>(/*filter*/);
87  if (!serviceRefs.empty())
88  {
89  int i = 0;
90  for(std::vector<us::ServiceReference<IToFDeviceFactory> >::iterator it = serviceRefs.begin(); it != serviceRefs.end(); ++it)
91  {
92  IToFDeviceFactory* service = context->GetService( *it );
93  if(service && (i == index))
94  {
95  return dynamic_cast<mitk::AbstractToFDeviceFactory*>(service)->ConnectToFDevice();
96  }
97  i++;
98  }
99  }
100  MITK_ERROR << "No device generated!";
101  return NULL;
102  }
103 }
std::vector< std::string > GetConnectedDevices()
ToFCameraDevice * GetInstanceOfDevice(int index)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
Virtual interface and base class for all Time-of-Flight device factories. The basic interface is in t...
Virtual interface and base class for all Time-of-Flight devices.
DataCollection - Class to facilitate loading/accessing structured data.
virtual std::string GetFactoryName()=0
GetFactoryName Get the human readable name of the factory.
void * GetService(const ServiceReferenceBase &reference)
std::vector< us::ServiceReference< IToFDeviceFactory > > m_RegisteredFactoryRefs
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
This is the base of class for all ToFDeviceFactories.
std::vector< std::string > GetRegisteredDeviceFactories()
std::vector< std::string > m_RegisteredFactoryNames