Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usServiceListenerEntry.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 
23 #include "usServiceListenerEntry_p.h"
24 #include "usServiceListenerHook_p.h"
25 
26 #include <cassert>
27 
28 US_BEGIN_NAMESPACE
29 
30 class ServiceListenerEntryData : public ServiceListenerHook::ListenerInfoData
31 {
32 public:
33 
34  ServiceListenerEntryData(ModuleContext* mc, const ServiceListenerEntry::ServiceListener& l,
35  void* data, const std::string& filter)
36  : ServiceListenerHook::ListenerInfoData(mc, l, data, filter)
37  , ldap()
38  , hashValue(0)
39  {
40  if (!filter.empty())
41  {
42  ldap = LDAPExpr(filter);
43  }
44  }
45 
46  ~ServiceListenerEntryData()
47  {
48  }
49 
50  LDAPExpr ldap;
51 
71  LDAPExpr::LocalCache local_cache;
72 
73  std::size_t hashValue;
74 
75 private:
76 
77  // purposely not implemented
78  ServiceListenerEntryData(const ServiceListenerEntryData&);
79  ServiceListenerEntryData& operator=(const ServiceListenerEntryData&);
80 };
81 
82 ServiceListenerEntry::ServiceListenerEntry(const ServiceListenerEntry& other)
83  : ServiceListenerHook::ListenerInfo(other)
84 {
85 }
86 
87 ServiceListenerEntry::ServiceListenerEntry(const ServiceListenerHook::ListenerInfo& info)
88  : ServiceListenerHook::ListenerInfo(info)
89 {
90  assert(info.d);
91 }
92 
93 ServiceListenerEntry::~ServiceListenerEntry()
94 {
95 }
96 
97 ServiceListenerEntry& ServiceListenerEntry::operator=(const ServiceListenerEntry& other)
98 {
99  d = other.d;
100  return *this;
101 }
102 
103 void ServiceListenerEntry::SetRemoved(bool removed) const
104 {
105  d->bRemoved = removed;
106 }
107 
108 ServiceListenerEntry::ServiceListenerEntry(ModuleContext* mc, const ServiceListener& l,
109  void* data, const std::string& filter)
110  : ServiceListenerHook::ListenerInfo(new ServiceListenerEntryData(mc, l, data, filter))
111 {
112 }
113 
114 const LDAPExpr& ServiceListenerEntry::GetLDAPExpr() const
115 {
116  return static_cast<ServiceListenerEntryData*>(d.Data())->ldap;
117 }
118 
119 LDAPExpr::LocalCache& ServiceListenerEntry::GetLocalCache() const
120 {
121  return static_cast<ServiceListenerEntryData*>(d.Data())->local_cache;
122 }
123 
124 void ServiceListenerEntry::CallDelegate(const ServiceEvent& event) const
125 {
126  d->listener(event);
127 }
128 
129 bool ServiceListenerEntry::operator==(const ServiceListenerEntry& other) const
130 {
131  return ((d->mc == NULL || other.d->mc == NULL) || d->mc == other.d->mc) &&
132  (d->data == other.d->data) && ServiceListenerCompare()(d->listener, other.d->listener);
133 }
134 
135 std::size_t ServiceListenerEntry::Hash() const
136 {
137  using namespace US_HASH_FUNCTION_NAMESPACE;
138 
139  if (static_cast<ServiceListenerEntryData*>(d.Data())->hashValue == 0)
140  {
141  static_cast<ServiceListenerEntryData*>(d.Data())->hashValue =
142  ((US_HASH_FUNCTION(ModuleContext*, d->mc) ^ (US_HASH_FUNCTION(void*, d->data) << 1)) >> 1) ^
143  (US_HASH_FUNCTION(US_SERVICE_LISTENER_FUNCTOR, d->listener) << 1);
144  }
145  return static_cast<ServiceListenerEntryData*>(d.Data())->hashValue;
146 }
147 
148 US_END_NAMESPACE
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
static void info(const char *fmt,...)
Definition: svm.cpp:100
US_BEGIN_NAMESPACE typedef US_SERVICE_LISTENER_FUNCTOR ServiceListener
US_HASH_FUNCTION_NAMESPACE_BEGIN return arg Hash()
US_MSVC_POP_WARNING US_HASH_FUNCTION_NAMESPACE_BEGIN return US_HASH_FUNCTION(us::ServiceRegistrationBasePrivate *, arg.d)