first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / octopi / library / synchronic / list_synchronizer.cpp
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
18 #include <structures/string_array.h>
19 #include <textual/string_manipulation.h>
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
35 list_synchronizer::~list_synchronizer()
36 {
37 }
38
39 outcome list_synchronizer::add_list(list_manager *to_add)
40 { return add_tentacle(to_add); }
41
42 outcome list_synchronizer::zap_list(const string_array &list_name)
43 { return zap_tentacle(list_name); }
44
45 bool list_synchronizer::update(const string_array &object_id)
46 {
47   lock_tentacles();
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   }
58   unlock_tentacles();
59   return to_return;
60 }
61
62 void list_synchronizer::clean(int older_than)
63 {
64   lock_tentacles();
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   }
69   unlock_tentacles();
70 }
71
72 } //namespace.
73