Line data Source code
1 :
2 : /* Copyright (c) 2012-2016, Stefan Eilemann <eile@eyescale.ch>
3 : *
4 : * This file is part of Collage <https://github.com/Eyescale/Collage>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef CO_OBJECTHANDLER_H
21 : #define CO_OBJECTHANDLER_H
22 :
23 : #include <co/api.h>
24 : #include <co/types.h>
25 :
26 : namespace co
27 : {
28 : /** Interface for entities which map and register objects. */
29 : class ObjectHandler
30 : {
31 : public:
32 : /**
33 : * Register a distributed object.
34 : *
35 : * Registering a distributed object makes this object the master
36 : * version. The object's identifier is used to map slave instances of the
37 : * object. Master versions of objects are typically writable and can commit
38 : * new versions of the distributed object.
39 : *
40 : * @param object the object instance.
41 : * @return true if the object was registered, false otherwise.
42 : * @version 1.0
43 : */
44 : virtual bool registerObject( Object* object ) = 0;
45 :
46 : /**
47 : * Deregister a distributed object.
48 : *
49 : * @param object the object instance.
50 : * @version 1.0
51 : */
52 : virtual void deregisterObject( Object* object ) = 0;
53 :
54 : /**
55 : * Start mapping a distributed object.
56 : *
57 : * @param object the object to map.
58 : * @param id the object identifier
59 : * @param version the version to map.
60 : * @param master the master node, may be invalid/0.
61 : * @return the request identifier for mapObjectSync().
62 : * @version 1.0
63 : */
64 : virtual uint32_t mapObjectNB( Object* object, const uint128_t& id,
65 : const uint128_t& version,
66 : NodePtr master ) = 0;
67 :
68 : /** Finalize the mapping of a distributed object. @version 1.0 */
69 : virtual bool mapObjectSync( const uint32_t requestID ) = 0;
70 :
71 : /** Unmap a mapped object. @version 1.0 */
72 : virtual void unmapObject( Object* object ) = 0;
73 :
74 : /** Convenience method to deregister or unmap an object. @version 1.0 */
75 : CO_API void releaseObject( Object* object );
76 :
77 : /**
78 : * Synchronize the local object with a remote object.
79 : *
80 : * The object is synchronized to the newest version of the first attached
81 : * object on the given master node matching the instanceID. No mapping is
82 : * established. When no master node is given, connectObjectMaster() is used
83 : * to find the node with the master instance. When CO_INSTANCE_ALL is given,
84 : * the first instance is used. Before a successful return,
85 : * applyInstanceData() is called on the calling thread to synchronize the
86 : * given object.
87 : *
88 : * @param object The local object instance to synchronize.
89 : * @param id the object identifier.
90 : * @param master The node where the synchronizing object is attached.
91 : * @param instanceID the instance identifier of the synchronizing
92 : * object.
93 : * @return A lunchbox::Future which will deliver the success status of
94 : * the operation on evaluation.
95 : * @version 1.1.1
96 : */
97 : virtual f_bool_t syncObject( Object* object, const uint128_t& id,
98 : NodePtr master,
99 : const uint32_t instanceID=CO_INSTANCE_ALL) = 0;
100 : protected:
101 : /** Construct a new object handler. @version 1.0 */
102 54 : ObjectHandler() {}
103 :
104 : /** Destroy this object handler. @version 1.0 */
105 53 : virtual ~ObjectHandler() {}
106 : };
107 : }
108 : #endif // CO_OBJECTHANDLER_H
|