feisty meow concerns codebase  2.140
list_manager.h
Go to the documentation of this file.
1 #ifndef LIST_MANAGER_CLASS
2 #define LIST_MANAGER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : list_manager *
7 * Author : Chris Koeritz *
8 * *
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 \*****************************************************************************/
17 
18 #include <octopus/tentacle.h>
19 
20 namespace synchronic {
21 
22 // forward.
23 class synchronizable;
24 class bundle_list;
25 
27 
35 {
36 public:
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.
42 
43  virtual ~list_manager();
44 
45  int entries() const; // returns the number of items held here.
46 
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).
50 
51  bool is_listed(const structures::string_array &classifier);
52  // returns true if the object with "classifier" exists in the list.
53 
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.
59 
60  void clean(int older_than);
61  // flushes out any items that haven't been updated in "older_than"
62  // microseconds.
63 
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.
67 
68  bool zap(const structures::string_array &classifier);
69  // returns true if we were able to find and remove the item held under
70  // the "classifier".
71 
72  void retrieve(bundle_list &to_fill) const;
73  // loads "to_fill" with a copy of the current set of attribute bundles.
74 
75  void reset();
76  // wipes out all objects that used to be listed.
77 
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
82  // currently unused.
83 
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.
88 
89  virtual void expunge(const octopi::octopus_entity &to_remove);
90  // cleans out any items held for the entity "to_remove".
91 
92 private:
93  bundle_list *_entries; // the set of elements that make up our list.
94  basis::mutex *_locking; // protects our contents.
95 
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.
99 };
100 
101 } //namespace.
102 
103 #endif
104 
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
Provides a way of identifying users of an octopus object.
Definition: entity_defs.h:35
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
Manages a service within an octopus by processing certain infotons.
Definition: tentacle.h:36
An array of strings with some additional helpful methods.
Definition: string_array.h:32
Provides a structure for managing a collection of synchronizables.
Definition: bundle_list.h:26
Supports distributed management of a list of object states.
Definition: list_manager.h:35
bool zap(const structures::string_array &classifier)
void retrieve(bundle_list &to_fill) const
list_manager(const structures::string_array &list_name, bool backgrounded)
bool update(const structures::string_array &classifier, int offset=0)
virtual void expunge(const octopi::octopus_entity &to_remove)
called to remove traces of the entity "to_remove".
void clean(int older_than)
bool is_listed(const structures::string_array &classifier)
virtual basis::outcome consume(octopi::infoton &to_chow, const octopi::octopus_request_id &item_id, basis::byte_array &transformed)
this is the main function that processes infotons for this tentacle.
virtual basis::outcome reconstitute(const structures::string_array &classifier, basis::byte_array &packed_form, octopi::infoton *&reformed)=0
regenerates an infoton from its packed form.
const structures::string_array & list_name() const
synchronizable * clone_object(const structures::string_array &classifier)
Encapsulates all of the attributes known for an object.