OpFlex Framework  1.7.0
StoreClient.h
Go to the documentation of this file.
1 /* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
6 /*
7  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
8  *
9  * This program and the accompanying materials are made available under the
10  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
11  * and is available at http://www.eclipse.org/legal/epl-v10.html
12  */
13 
14 #ifndef MODB_STORECLIENT_H
15 #define MODB_STORECLIENT_H
16 
17 #include <boost/noncopyable.hpp>
18 
19 #include "opflex/modb/URI.h"
21 #include "opflex/ofcore/OFTypes.h"
22 
23 namespace opflex {
24 namespace modb {
25 
26 class Region;
27 class ObjectStore;
28 
29 namespace mointernal {
30 
37 class StoreClient : private boost::noncopyable {
38 public:
44  const std::string& getOwner() const;
45 
56  void put(class_id_t class_id,
57  const URI& uri,
58  const OF_SHARED_PTR<const ObjectInstance>& oi);
59 
72  bool putIfModified(class_id_t class_id,
73  const URI& uri,
74  const OF_SHARED_PTR<const ObjectInstance>& oi);
75 
86  bool isPresent(class_id_t class_id, const URI& uri) const;
87 
99  OF_SHARED_PTR<const ObjectInstance> get(class_id_t class_id,
100  const URI& uri) const;
101 
112  bool get(class_id_t class_id, const URI& uri,
113  /*out*/ OF_SHARED_PTR<const ObjectInstance>& oi) const;
114 
118  typedef OF_UNORDERED_MAP<URI, class_id_t> notif_t;
119 
135  bool remove(class_id_t class_id, const URI& uri,
136  bool recursive,
137  /* out */ notif_t* notifs = NULL);
138 
155  bool addChild(class_id_t parent_class,
156  const URI& parent_uri,
157  prop_id_t parent_prop,
158  class_id_t child_class,
159  const URI& child_uri);
160 
173  void delChild(class_id_t parent_class,
174  const URI& parent_uri,
175  prop_id_t parent_prop,
176  class_id_t child_class,
177  const URI& child_uri);
178 
189  std::pair<URI, prop_id_t> getParent(class_id_t child_class,
190  const URI& child);
191 
202  bool getParent(class_id_t child_class, const URI& child,
203  /* out */ std::pair<URI, prop_id_t>& parent);
204 
216  void getChildren(class_id_t parent_class,
217  const URI& parent_uri,
218  prop_id_t parent_prop,
219  class_id_t child_class,
220  /* out */ std::vector<URI>& output);
221 
232  void removeChildren(class_id_t class_id,
233  const URI& uri,
234  notif_t* notifs);
235 
241  void queueNotification(class_id_t class_id, const URI& uri,
242  /* out */ notif_t& notifs);
243 
250  void deliverNotifications(const notif_t& notifs);
251 
259  void getObjectsForClass(class_id_t class_id,
260  /* out */ OF_UNORDERED_SET<URI>& output);
261 
262 private:
263 
264  friend class opflex::modb::Region;
265  friend class opflex::modb::ObjectStore;
266 
267  StoreClient(ObjectStore* store, Region* region,
268  bool readOnly = false);
269 
270  ObjectStore* store;
271  Region* region;
272  bool readOnly;
273 };
274 
275 } /* namespace mointernal */
276 } /* namespace modb */
277 } /* namespace opflex */
278 
279 #endif /* MODB_STORECLIENT_H */
bool addChild(class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, const URI &child_uri)
Add a parent/child relationship between a parent URI (from any region) to a child URI (in this region...
OF_UNORDERED_MAP< URI, class_id_t > notif_t
A map to store queued notifications.
Definition: StoreClient.h:118
A client for accessing the object store scoped to an owner.
Definition: StoreClient.h:37
void queueNotification(class_id_t class_id, const URI &uri, notif_t &notifs)
Queue notifications for dispatch to the given URI and its parents.
void getObjectsForClass(class_id_t class_id, OF_UNORDERED_SET< URI > &output)
Get a set of all objects with the given class ID.
void delChild(class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, const URI &child_uri)
Remove a parent/child relationship between a parent URI and a child URI.
const std::string & getOwner() const
Get the owner of this store client.
std::pair< URI, prop_id_t > getParent(class_id_t child_class, const URI &child)
Get the parent for the given child URI.
bool isPresent(class_id_t class_id, const URI &uri) const
Check whether an item exists in the store.
void put(class_id_t class_id, const URI &uri, const OF_SHARED_PTR< const ObjectInstance > &oi)
Set the specified URI to the provided object instance, replacing any existing value.
void getChildren(class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, std::vector< URI > &output)
Get the children of the parent URI and property and put the result into the supplied vector...
void removeChildren(class_id_t class_id, const URI &uri, notif_t *notifs)
Remove all the children of the given object, exluding the object itself.
uint64_t class_id_t
A unique class ID.
Definition: PropertyInfo.h:34
Interface definition file for ObjectInstance.
A URI is used to identify managed objects in the MODB.
Definition: URI.h:43
uint64_t prop_id_t
A unique property ID.
Definition: PropertyInfo.h:39
Interface definition file for URIs.
bool putIfModified(class_id_t class_id, const URI &uri, const OF_SHARED_PTR< const ObjectInstance > &oi)
Set the specified URI to the provided object instance if it has been modified, atomically.
void deliverNotifications(const notif_t &notifs)
Deliver the notifications to the object store notification queue.