Turi Create  4.0
object_factory_impl.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef CPPIPC_COMMON_OBJECT_FACTORY_IMPL_HPP
7 #define CPPIPC_COMMON_OBJECT_FACTORY_IMPL_HPP
8 #include <core/system/cppipc/common/object_factory_base.hpp>
9 #include <core/system/cppipc/server/comm_server.hpp>
10 #include <map>
11 #include <string>
12 #include <functional>
13 #include <boost/algorithm/string/predicate.hpp>
14 
15 namespace cppipc {
16 
17 /**
18  * \internal
19  * \ingroup cppipc
20  * An implementation of the object factory interface.
21  * This is a special object created by the comm_server and is used to provide
22  * the comm_server with an external interface; for instance to manage the
23  * construction and destruction of objects
24  *
25  */
27  public:
28  std::map<std::string, std::function<std::shared_ptr<void>()> > constructors;
29  comm_server& srv;
30 
31  object_factory_impl(comm_server& comm):srv(comm) { }
32 
33  /**
34  * creates and registers an object of type object_type_name
35  */
36  size_t make_object(std::string object_type_name);
37 
38  /**
39  * Deletes the object of type object_id
40  */
41  void delete_object(size_t object_id);
42 
43  /**
44  * Ping test. Replies with the ping value
45  */
46  std::string ping(std::string pingval);
47 
48  /**
49  * Get the address on which the server is publishing status updates.
50  */
51  std::string get_status_publish_address();
52 
53  /**
54  * Get the address which the server is receiving control messages
55  */
56  std::string get_control_address();
57 
58  void sync_objects(std::vector<size_t> object_ids, bool input_sorted);
59 
60  /**
61  * \internal
62  * Stores a constructor for an object type
63  */
64  void add_constructor(std::string object_type_name,
65  std::function<std::shared_ptr<void>()> constructor) {
66  constructors[object_type_name] = constructor;
67  }
68 };
69 
70 
71 
72 
73 } // cppipc
74 #endif
void sync_objects(std::vector< size_t > object_ids, bool input_sorted)
std::string get_control_address()
std::string get_status_publish_address()
size_t make_object(std::string object_type_name)
void delete_object(size_t object_id)
std::string ping(std::string pingval)
void add_constructor(std::string object_type_name, std::function< std::shared_ptr< void >()> constructor)