Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usServiceEvent.cpp
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 #include "usServiceEvent.h"
23 
24 #include "usServiceProperties.h"
25 
26 US_BEGIN_NAMESPACE
27 
28 class ServiceEventData : public SharedData
29 {
30 public:
31 
32  ServiceEventData(const ServiceEvent::Type& type, const ServiceReferenceBase& reference)
33  : type(type), reference(reference)
34  {
35 
36  }
37 
38  ServiceEventData(const ServiceEventData& other)
39  : SharedData(other), type(other.type), reference(other.reference)
40  {
41 
42  }
43 
44  const ServiceEvent::Type type;
45  const ServiceReferenceBase reference;
46 
47 private:
48 
49  // purposely not implemented
50  ServiceEventData& operator=(const ServiceEventData&);
51 };
52 
53 ServiceEvent::ServiceEvent()
54  : d(0)
55 {
56 
57 }
58 
60 {
61 
62 }
63 
65 {
66  return !d;
67 }
68 
70  : d(new ServiceEventData(type, reference))
71 {
72 
73 }
74 
76  : d(other.d)
77 {
78 
79 }
80 
82 {
83  d = other.d;
84  return *this;
85 }
86 
88 {
89  return d->reference;
90 }
91 
93 {
94  return d->type;
95 }
96 
97 std::ostream& operator<<(std::ostream& os, const ServiceEvent::Type& type)
98 {
99  switch(type)
100  {
101  case ServiceEvent::MODIFIED: return os << "MODIFIED";
102  case ServiceEvent::MODIFIED_ENDMATCH: return os << "MODIFIED_ENDMATCH";
103  case ServiceEvent::REGISTERED: return os << "REGISTERED";
104  case ServiceEvent::UNREGISTERING: return os << "UNREGISTERING";
105 
106  default: return os << "unknown service event type (" << static_cast<int>(type) << ")";
107  }
108 }
109 
110 std::ostream& operator<<(std::ostream& os, const ServiceEvent& event)
111 {
112  if (event.IsNull()) return os << "NONE";
113 
114  os << event.GetType();
115 
116  ServiceReferenceU sr = event.GetServiceReference();
117  if (sr)
118  {
119  // Some events will not have a service reference
120  long int sid = any_cast<long int>(sr.GetProperty(ServiceConstants::SERVICE_ID()));
121  os << " " << sid;
122 
123  Any classes = sr.GetProperty(ServiceConstants::OBJECTCLASS());
124  os << " objectClass=" << classes.ToString() << ")";
125  }
126 
127  return os;
128 }
129 
130 US_END_NAMESPACE
ServiceEvent & operator=(const ServiceEvent &other)
bool IsNull() const
ServiceReferenceU GetServiceReference() const
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
Definition: usAny.h:163
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
Type GetType() const
US_Core_EXPORT const std::string & OBJECTCLASS()
std::string ToString() const
Definition: usAny.h:257
US_Core_EXPORT const std::string & SERVICE_ID()