OpFlex Framework  1.3.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/unordered_map.hpp>
18 #include <boost/noncopyable.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/unordered_set.hpp>
21 
22 #include "opflex/modb/URI.h"
24 
25 namespace opflex {
26 namespace modb {
27 
28 class Region;
29 class ObjectStore;
30 
31 namespace mointernal {
32 
39 class StoreClient : private boost::noncopyable {
40 public:
46  const std::string& getOwner() const;
47 
58  void put(class_id_t class_id,
59  const URI& uri,
60  const boost::shared_ptr<const ObjectInstance>& oi);
61 
74  bool putIfModified(class_id_t class_id,
75  const URI& uri,
76  const boost::shared_ptr<const ObjectInstance>& oi);
77 
88  bool isPresent(class_id_t class_id, const URI& uri) const;
89 
101  boost::shared_ptr<const ObjectInstance> get(class_id_t class_id,
102  const URI& uri) const;
103 
114  bool get(class_id_t class_id, const URI& uri,
115  /*out*/ boost::shared_ptr<const ObjectInstance>& oi) const;
116 
120  typedef boost::unordered_map<URI, class_id_t> notif_t;
121 
137  bool remove(class_id_t class_id, const URI& uri,
138  bool recursive,
139  /* out */ notif_t* notifs = NULL);
140 
157  bool addChild(class_id_t parent_class,
158  const URI& parent_uri,
159  prop_id_t parent_prop,
160  class_id_t child_class,
161  const URI& child_uri);
162 
175  void delChild(class_id_t parent_class,
176  const URI& parent_uri,
177  prop_id_t parent_prop,
178  class_id_t child_class,
179  const URI& child_uri);
180 
191  std::pair<URI, prop_id_t> getParent(class_id_t child_class,
192  const URI& child);
193 
204  bool getParent(class_id_t child_class, const URI& child,
205  /* out */ std::pair<URI, prop_id_t>& parent);
206 
218  void getChildren(class_id_t parent_class,
219  const URI& parent_uri,
220  prop_id_t parent_prop,
221  class_id_t child_class,
222  /* out */ std::vector<URI>& output);
223 
234  void removeChildren(class_id_t class_id,
235  const URI& uri,
236  notif_t* notifs);
237 
243  void queueNotification(class_id_t class_id, const URI& uri,
244  /* out */ notif_t& notifs);
245 
252  void deliverNotifications(const notif_t& notifs);
253 
261  void getObjectsForClass(class_id_t class_id,
262  /* out */ boost::unordered_set<URI>& output);
263 
264 private:
265 
266  friend class opflex::modb::Region;
267  friend class opflex::modb::ObjectStore;
268 
269  StoreClient(ObjectStore* store, Region* region,
270  bool readOnly = false);
271 
272  ObjectStore* store;
273  Region* region;
274  bool readOnly;
275 };
276 
277 } /* namespace mointernal */
278 } /* namespace modb */
279 } /* namespace opflex */
280 
281 #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...
A client for accessing the object store scoped to an owner.
Definition: StoreClient.h:39
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 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.
void getObjectsForClass(class_id_t class_id, boost::unordered_set< URI > &output)
Get a set of all objects with the given class ID.
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 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:36
Interface definition file for ObjectInstance.
A URI is used to identify managed objects in the MODB.
Definition: URI.h:41
uint64_t prop_id_t
A unique property ID.
Definition: PropertyInfo.h:41
bool putIfModified(class_id_t class_id, const URI &uri, const boost::shared_ptr< const ObjectInstance > &oi)
Set the specified URI to the provided object instance if it has been modified, atomically.
Interface definition file for URIs.
void put(class_id_t class_id, const URI &uri, const boost::shared_ptr< const ObjectInstance > &oi)
Set the specified URI to the provided object instance, replacing any existing value.
boost::unordered_map< URI, class_id_t > notif_t
A map to store queued notifications.
Definition: StoreClient.h:120
void deliverNotifications(const notif_t &notifs)
Deliver the notifications to the object store notification queue.