CustusX  2021.05.28-dev+develop.ccf84
An IGT application
cxServiceTrackerCustomizer.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXSERVICETRACKERCUSTOMIZER_H_
13 #define CXSERVICETRACKERCUSTOMIZER_H_
14 
15 #include <boost/function.hpp>
16 
17 #include "ctkServiceTracker.h"
18 #include "ctkServiceTrackerCustomizer.h"
19 #include <iostream>
20 
21 namespace cx {
32 template<class T >
33 class ServiceTrackerCustomizer : public ctkServiceTrackerCustomizer<T*>
34 {
35 public:
38 
39  virtual T* addingService(const ctkServiceReference &reference)
40  {
41  T* service = reference.getPlugin()->getPluginContext()->getService<T>(reference);
42  if(mServiceAddedFunction)
43  mServiceAddedFunction(service);
44  return service;
45  }
46  virtual void modifiedService(const ctkServiceReference &reference, T* service)
47  {
48  if(mServiceModifiedFunction)
49  mServiceModifiedFunction(service);
50  //TODO when does this happen? untested
51  }
52  virtual void removedService(const ctkServiceReference &reference, T* service)
53  {
54  if(mServiceRemovedFunction)
55  mServiceRemovedFunction(service);
56  reference.getPlugin()->getPluginContext()->ungetService(reference);
57  }
58 
59  void setServiceAddedCallback(boost::function<void (T*)> func)
60  {
61  mServiceAddedFunction = func;
62  }
63  void setServiceModifiedCallback(boost::function<void (T*)> func)
64  {
65  mServiceModifiedFunction = func;
66  }
67  void setServiceRemovedCallback(boost::function<void (T*)> func)
68  {
69  mServiceRemovedFunction = func;
70  }
71 
72 private:
73  boost::function<void (T*)> mServiceAddedFunction;
74  boost::function<void (T*)> mServiceModifiedFunction;
75  boost::function<void (T*)> mServiceRemovedFunction;
76 };
77 } /* namespace cx */
78 
79 #endif /* CXSERVICETRACKERCUSTOMIZER_H_ */
void setServiceAddedCallback(boost::function< void(T *)> func)
void setServiceModifiedCallback(boost::function< void(T *)> func)
void setServiceRemovedCallback(boost::function< void(T *)> func)
Notify changes in a service lifecycle.
virtual T * addingService(const ctkServiceReference &reference)
virtual void modifiedService(const ctkServiceReference &reference, T *service)
virtual void removedService(const ctkServiceReference &reference, T *service)
Namespace for all CustusX production code.