1 #ifndef LIST_MANAGER_CLASS
2 #define LIST_MANAGER_CLASS
4 /*****************************************************************************\
6 * Name : list_manager *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2002-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <octopus/tentacle.h>
20 namespace synchronic {
26 //! Supports distributed management of a list of object states.
28 An object may have a collection of attributes which are important to keep
29 up to date. The list_manager provides a means to keep that information
30 relevant given periodic updates to the state information by the entity in
31 charge of the actual object.
34 class list_manager : public octopi::tentacle
37 list_manager(const structures::string_array &list_name, bool backgrounded);
38 // given the root of the "list_name", this will administrate the list.
39 // all entries in the list must have "list_name" as their prefix.
40 // if "backgrounded" is true, then this list will consume its requests
41 // on a thread. otherwise it deals with them immediately.
43 virtual ~list_manager();
45 int entries() const; // returns the number of items held here.
47 const structures::string_array &list_name() const;
48 // returns the list name this was constructed with (which is the same
49 // as the group for this object).
51 bool is_listed(const structures::string_array &classifier);
52 // returns true if the object with "classifier" exists in the list.
54 bool update(const structures::string_array &classifier, int offset = 0);
55 // returns true if the object with "classifier" could be found and its
56 // last update timestamp set to the current time if "offset" is zero.
57 // if "offset" is negative, then the time will be updated to some time
58 // before now. if positive, then it's updated to a time after now.
60 void clean(int older_than);
61 // flushes out any items that haven't been updated in "older_than"
64 synchronizable *clone_object(const structures::string_array &classifier);
65 // returns a clone of the object listed for "classifier" or NULL_POINTER if there
66 // are none matching. the returned object must be destroyed if non-null.
68 bool zap(const structures::string_array &classifier);
69 // returns true if we were able to find and remove the item held under
72 void retrieve(bundle_list &to_fill) const;
73 // loads "to_fill" with a copy of the current set of attribute bundles.
76 // wipes out all objects that used to be listed.
78 virtual basis::outcome consume(octopi::infoton &to_chow,
79 const octopi::octopus_request_id &item_id,
80 basis::byte_array &transformed);
81 // processes a request encapsulated in "to_chow". the "item_id" is
84 virtual basis::outcome reconstitute(const structures::string_array &classifier,
85 basis::byte_array &packed_form, octopi::infoton * &reformed) = 0;
86 // recovers the original form "reformed" from a "packed_form" of the
87 // object. this must be provided by derived list_manager objects.
89 virtual void expunge(const octopi::octopus_entity &to_remove);
90 // cleans out any items held for the entity "to_remove".
93 bundle_list *_entries; // the set of elements that make up our list.
94 basis::mutex *_locking; // protects our contents.
96 int locked_find(const structures::string_array &classifier);
97 // locates the item with the "classifier" in this list. if it's present,
98 // a non-negative index number is returned.