/*============================================================================= Library: CppMicroServices Copyright (c) The CppMicroServices developers. See the COPYRIGHT file at the top-level directory of this distribution and at https://github.com/CppMicroServices/CppMicroServices/COPYRIGHT . Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef CPPMICROSERVICES_SERVICETRACKERPRIVATE_H #define CPPMICROSERVICES_SERVICETRACKERPRIVATE_H #include "cppmicroservices/BundleContext.h" #include "cppmicroservices/LDAPFilter.h" #include "cppmicroservices/ServiceReference.h" #include "cppmicroservices/detail/Threads.h" namespace cppmicroservices { namespace detail { /** * \ingroup MicroServices */ template class ServiceTrackerPrivate : MultiThreaded<> { public: typedef typename TTT::TrackedType T; typedef typename TTT::TrackedParmType TrackedParmType; ServiceTrackerPrivate(ServiceTracker* st, const BundleContext& context, const ServiceReference& reference, ServiceTrackerCustomizer* customizer); ServiceTrackerPrivate(ServiceTracker* st, const BundleContext& context, const std::string& clazz, ServiceTrackerCustomizer* customizer); ServiceTrackerPrivate(ServiceTracker* st, const BundleContext& context, const LDAPFilter& filter, ServiceTrackerCustomizer* customizer); ~ServiceTrackerPrivate(); /** * Returns the list of initial ServiceReferences that will be * tracked by this ServiceTracker. * * @param className The class name with which the service was registered, or * null for all services. * @param filterString The filter criteria or null for all * services. * @return The list of initial ServiceReferences. * @throws std::invalid_argument If the specified filterString has an * invalid syntax. */ std::vector> GetInitialReferences( const std::string& className, const std::string& filterString); void GetServiceReferences_unlocked(std::vector>& refs, TrackedService* t) const; /** * The Bundle Context used by this ServiceTracker. */ BundleContext context; /** * The filter used by this ServiceTracker which specifies the * search criteria for the services to track. */ LDAPFilter filter; /** * The ServiceTrackerCustomizer for this tracker. */ ServiceTrackerCustomizer* customizer; /** * Filter string for use when adding the ServiceListener. If this field is * set, then certain optimizations can be taken since we don't have a user * supplied filter. */ std::string listenerFilter; /** * This token corresponds to the ServiceListener, whenever it is added. * Otherwise, it represents an invalid token. */ ListenerToken listenerToken; /** * Class name to be tracked. If this field is set, then we are tracking by * class name. */ std::string trackClass; /** * Reference to be tracked. If this field is set, then we are tracking a * single ServiceReference. */ ServiceReference trackReference; /** * Tracked services: ServiceReference -> customized Object and * ServiceListenerEntry object */ Atomic>> trackedService; /** * Accessor method for the current TrackedService object. This method is only * intended to be used by the unsynchronized methods which do not modify the * trackedService field. * * @return The current Tracked object. */ std::shared_ptr> Tracked() const; /** * Called by the TrackedService object whenever the set of tracked services is * modified. Clears the cache. */ /* * This method must not be synchronized since it is called by TrackedService while * TrackedService is synchronized. We don't want synchronization interactions * between the listener thread and the user thread. */ void Modified(); /** * Cached ServiceReference for getServiceReference. */ mutable Atomic> cachedReference; /** * Cached service object for GetService. */ mutable Atomic> cachedService; private: inline ServiceTracker* q_func() { return static_cast*>(q_ptr); } inline const ServiceTracker* q_func() const { return static_cast*>(q_ptr); } friend class ServiceTracker; ServiceTracker* const q_ptr; }; } // namespace detail } // namespace cppmicroservices #include "cppmicroservices/detail/ServiceTrackerPrivate.tpp" #endif // CPPMICROSERVICES_SERVICETRACKERPRIVATE_H