libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
autoservice.hpp
Go to the documentation of this file.
1 
2 #pragma once
3 
4 /*
5  ** Copyright (C) 2013 Aldebaran Robotics
6  ** See COPYING for the licence
7 */
8 
9 #ifndef _QIMESSAGING_AUTOSERVICE_HPP_
10 #define _QIMESSAGING_AUTOSERVICE_HPP_
11 
12 #include <string>
13 #include <stdexcept>
14 #include <boost/thread/mutex.hpp>
15 #include <qi/session.hpp>
16 #include <qi/anyobject.hpp>
17 #include <qi/trackable.hpp>
18 
19 namespace qi
20 {
21 
22  namespace detail
23  {
24  template <typename T>
25  class Keeper;
26  }
27 
37  template <typename T>
38  class AutoService : public qi::Trackable<AutoService<T> >, public qi::detail::GenericObjectBounce<AutoService<T> >
39  {
40  public:
49  AutoService(const std::string& name, qi::SessionPtr session);
50 
51  ~AutoService();
52 
70  T& operator*();
71  T* get();
72  const T* get() const;
73 
80 
85 
90 
92 
93  private:
94  void onServiceModified(const qi::Future<qi::AnyObject>& future);
95  void onServiceAdded(const std::string& name);
96  void onServiceRemoved(const std::string& name);
97 
98  mutable boost::mutex _mutex;
99  SessionPtr _session;
100  qi::Object<T> _object;
101  std::string _name;
102  qi::Promise<void> _promise;
103  };
104 
106 }
107 
108 #include "detail/autoservice.hxx"
109 
110 #endif
qi::GenericObject * asGenericObject() const
boost::shared_ptr< Session > SessionPtr
Definition: session.hpp:34
qi::Signal< void > serviceAdded
Definition: autoservice.hpp:84
qi::detail::Keeper< T > operator->()
Definition: autoservice.hxx:80
qi::FutureSync< void > waitForReady()
AutoService(const std::string &name, qi::SessionPtr session)
Definition: autoservice.hxx:6
Object tracking by blocking destruction while shared pointers are present.
Definition: trackable.hpp:45
qi::Signal< void > serviceRemoved
Definition: autoservice.hpp:89