feisty meow concerns codebase  2.140
list_synchronizer.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : list_synchronizer *
4 * Author : Chris Koeritz *
5 * *
6 *******************************************************************************
7 * Copyright (c) 2002-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
14 
15 #include "list_manager.h"
16 #include "list_synchronizer.h"
17 
20 
21 using namespace basis;
22 using namespace structures;
23 using namespace textual;
24 
25 namespace synchronic {
26 
27 const int MAX_PER_ENT = 10 * MEGABYTE;
28  // our arbitrary limit for how much we allow the entity data bin to store.
29 
30 list_synchronizer::list_synchronizer()
31 : octopus(string_manipulation::make_random_name(), MAX_PER_ENT)
32 {
33 }
34 
36 {
37 }
38 
40 { return add_tentacle(to_add); }
41 
43 { return zap_tentacle(list_name); }
44 
46 {
48  bool to_return = false;
49  for (int i = 0; i < locked_tentacle_count(); i++) {
50  list_manager *t = dynamic_cast<list_manager *>(locked_get_tentacle(i));
51  if (!t) continue;
52  if (t->list_name().prefix_compare(object_id)) {
53  // this is the right one to ask about the object.
54  to_return = t->update(object_id);
55  break;
56  }
57  }
59  return to_return;
60 }
61 
62 void list_synchronizer::clean(int older_than)
63 {
65  for (int i = 0; i < locked_tentacle_count(); i++) {
66  list_manager *t = dynamic_cast<list_manager *>(locked_get_tentacle(i));
67  if (t) t->clean(older_than);
68  }
70 }
71 
72 } //namespace.
73 
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
tentacle * locked_get_tentacle(int indy)
access indy'th tentacle.
Definition: octopus.cpp:184
void unlock_tentacles()
unlocks the list.
Definition: octopus.cpp:176
basis::outcome add_tentacle(tentacle *to_add, bool filter=false)
hooks a tentacle in to provide processing of one type of infoton.
Definition: octopus.cpp:253
int locked_tentacle_count()
number of tentacles.
Definition: octopus.cpp:180
basis::outcome zap_tentacle(const structures::string_array &group_name)
similar to remove_tentacle(), but destroys the tentacle.
Definition: octopus.cpp:245
void lock_tentacles()
locks the tentacle list for use with locked_get_tentacle.
Definition: octopus.cpp:174
An array of strings with some additional helpful methods.
Definition: string_array.h:32
bool prefix_compare(const string_array &second) const
Returns true if all of the elements in this are the same in "second".
Definition: string_array.h:98
Supports distributed management of a list of object states.
Definition: list_manager.h:35
bool update(const structures::string_array &classifier, int offset=0)
void clean(int older_than)
const structures::string_array & list_name() const
bool update(const structures::string_array &object_id)
basis::outcome add_list(list_manager *to_add)
basis::outcome zap_list(const structures::string_array &list_name)
Provides various functions for massaging strings.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
const int MEGABYTE
Number of bytes in a megabyte.
Definition: definitions.h:135
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
const int MAX_PER_ENT