list_manager.h

Go to the documentation of this file.
00001 #ifndef LIST_MANAGER_CLASS
00002 #define LIST_MANAGER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : list_manager                                                      *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "dll_list_synch.h"
00019 
00020 #include <octopus/tentacle.h>
00021 
00022 // forward.
00023 class attribute_bundle;
00024 class bundle_list;
00025 
00027 
00034 class LIST_SYNCHRONIZER_CLASS_STYLE list_manager : public tentacle
00035 {
00036 public:
00037   list_manager(const string_array &list_name, bool backgrounded);
00038     // given the root of the "list_name", this will administrate the list.
00039     // all entries in the list must have "list_name" as their prefix.
00040     // if "backgrounded" is true, then this list will consume its requests
00041     // on a thread.  otherwise it deals with them immediately.
00042 
00043   virtual ~list_manager();
00044 
00045   int entries() const;  // returns the number of items held here.
00046 
00047   const string_array &list_name() const;
00048     // returns the list name this was constructed with (which is the same
00049     // as the group for this object).
00050 
00051   bool is_listed(const string_array &classifier);
00052     // returns true if the object with "classifier" exists in the list.
00053 
00054   bool update(const string_array &classifier, int offset = 0);
00055     // returns true if the object with "classifier" could be found and its
00056     // last update timestamp set to the current time if "offset" is zero.
00057     // if "offset" is negative, then the time will be updated to some time
00058     // before now.  if positive, then it's updated to a time after now.
00059 
00060   void clean(int older_than);
00061     // flushes out any items that haven't been updated in "older_than"
00062     // microseconds.
00063 
00064   attribute_bundle *clone_object(const string_array &classifier);
00065     // returns a clone of the object listed for "classifier" or NIL if there
00066     // are none matching.  the returned object must be destroyed if non-NIL.
00067 
00068   bool zap(const string_array &classifier);
00069     // returns true if we were able to find and remove the item held under
00070     // the "classifier".
00071 
00072   void retrieve(bundle_list &to_fill) const;
00073     // loads "to_fill" with a copy of the current set of attribute bundles.
00074 
00075   void reset();
00076     // wipes out all objects that used to be listed.
00077 
00078   virtual outcome consume(infoton &to_chow, const octopus_request_id &item_id,
00079           byte_array &transformed);
00080     // processes a request encapsulated in "to_chow".  the "item_id" is
00081     // currently unused.
00082 
00083   virtual outcome reconstitute(const string_array &classifier,
00084           byte_array &packed_form, infoton * &reformed) = 0;
00085     // recovers the original form "reformed" from a "packed_form" of the
00086     // object.  this must be provided by derived list_manager objects.
00087 
00088   virtual void expunge(const octopus_entity &to_remove);
00089     // cleans out any items held for the entity "to_remove".
00090 
00091 private:
00092   bundle_list *_entries;  // the set of elements that make up our list.
00093   mutex *_locking;  // protects our contents.
00094 
00095   int locked_find(const string_array &classifier);
00096     // locates the item with the "classifier" in this list.  if it's present,
00097     // a non-negative index number is returned.
00098 };
00099 
00100 #endif
00101 

Generated on Fri Nov 28 04:29:15 2008 for HOOPLE Libraries by  doxygen 1.5.1