Merge branch 'master' of feistymeow.org:feisty_meow into dev
[feisty_meow.git] / octopi / library / octopus / entity_data_bin.cpp
index 080e758c3e312a6a905dc0d850cdaea7cb8dcb2e..a1584e0d52c4e1169a3e567a23a1a31a5711260e 100644 (file)
@@ -64,7 +64,7 @@ public:
   time_stamp _when_added;  // when the data became available.
 
   infoton_holder(const octopus_request_id &id = octopus_request_id(),
-      infoton *item = NIL)
+      infoton *item = NULL_POINTER)
   : _item(item), _id(id), _when_added() {}
 
   ~infoton_holder() { WHACK(_item); }
@@ -140,7 +140,7 @@ struct apply_struct
   int _decay_interval;  // how long are items allowed to live?
 
   apply_struct(int &items_held)
-      : _empty_baskets(NIL), _any_item(NIL), _items_held(items_held),
+      : _empty_baskets(NULL_POINTER), _any_item(NULL_POINTER), _items_held(items_held),
         _decay_interval(0) {}
 };
 
@@ -189,7 +189,7 @@ bool scramble_applier(const octopus_entity &formal(key), entity_basket &bask,
 {
   #undef static_class_name
   #define static_class_name() "entity_data_bin"
-//  FUNCDEF("scramble_applier");
+  FUNCDEF("scramble_applier");
   int *county = (int *)data_link;
   *county += bask.elements();
   return true;
@@ -219,7 +219,7 @@ int entity_data_bin::scramble_counter()
 bool entity_data_bin::add_item(infoton *to_add,
     const octopus_request_id &orig_id)
 {
-//  FUNCDEF("add_item");
+  FUNCDEF("add_item");
   GRAB_LOCK;
   // create a record to add to the appropriate bin.
   infoton_holder *holder = new infoton_holder(orig_id, to_add);
@@ -241,6 +241,7 @@ bool entity_data_bin::add_item(infoton *to_add,
 
   if (current_size + to_add->packed_size() > _max_per_ent) {
     WHACK(holder);
+LOG(astring("size limit would be exceeded if we stored this product"));
     return false;
   }
   
@@ -253,10 +254,8 @@ bool entity_data_bin::add_item(infoton *to_add,
 bool any_item_applier(const octopus_entity &formal(key), entity_basket &bask,
     void *data_link)
 {
-//#ifdef DEBUG_ENTITY_DATA_BIN
-//  #define static_class_name() "entity_data_bin"
-//  FUNCDEF("any_item_applier");
-//#endif
+  #define static_class_name() "entity_data_bin"
+  FUNCDEF("any_item_applier");
   apply_struct *apple = (apply_struct *)data_link;
   // check the basket to see if it has any items.
   if (!bask.elements()) {
@@ -276,7 +275,7 @@ infoton *entity_data_bin::acquire_for_any(octopus_request_id &id)
   GRAB_LOCK;
   apply_struct apple(_items_held);
   _table->apply(any_item_applier, &apple);
-  if (!apple._any_item) return NIL;
+  if (!apple._any_item) return NULL_POINTER;
   DUMP_STATE;
   // retrieve the information from our basket that was provided.
   infoton_holder *found = apple._any_item->acquire(0);
@@ -288,10 +287,10 @@ infoton *entity_data_bin::acquire_for_any(octopus_request_id &id)
 #endif
     _table->zap(found->_id._entity);
   }
-  apple._any_item = NIL;
+  apple._any_item = NULL_POINTER;
   infoton *to_return = found->_item;
   id = found->_id;
-  found->_item = NIL;  // clear so it won't be whacked.
+  found->_item = NULL_POINTER;  // clear so it won't be whacked.
   WHACK(found);
   _items_held--;
 //#ifdef DEBUG_ENTITY_DATA_BIN
@@ -304,7 +303,7 @@ infoton *entity_data_bin::acquire_for_any(octopus_request_id &id)
 int entity_data_bin::acquire_for_entity(const octopus_entity &requester,
     infoton_list &items, int maximum_size)
 {
-//  FUNCDEF("acquire_for_entity [multiple]");
+  FUNCDEF("acquire_for_entity [multiple]");
   // this method does not grab the lock because it simply composes other
   // class methods without interacting with class data members.
   items.reset();
@@ -329,22 +328,22 @@ infoton *entity_data_bin::acquire_for_entity(const octopus_entity &requester,
   FUNCDEF("acquire_for_entity [single]");
   id = octopus_request_id();  // reset it.
   GRAB_LOCK;
-  infoton *to_return = NIL;
+  infoton *to_return = NULL_POINTER;
   entity_basket *bask = _table->find(requester);
   if (!bask) {
-    return NIL;
+    return NULL_POINTER;
   }
   if (!bask->elements()) {
 #ifdef DEBUG_ENTITY_DATA_BIN
     LOG(astring("tossing empty basket ") + requester.mangled_form());
 #endif
     _table->zap(requester);
-    return NIL;
+    return NULL_POINTER;
   }
   DUMP_STATE;
   id = bask->get(0)->_id;
   to_return = bask->borrow(0)->_item;
-  bask->borrow(0)->_item = NIL;
+  bask->borrow(0)->_item = NULL_POINTER;
   bask->zap(0, 0);
   if (!bask->elements()) {
 #ifdef DEBUG_ENTITY_DATA_BIN
@@ -363,21 +362,21 @@ infoton *entity_data_bin::acquire_for_entity(const octopus_entity &requester,
 infoton *entity_data_bin::acquire_for_identifier(const octopus_request_id &id)
 {
   FUNCDEF("acquire_for_identifier");
-  infoton *to_return = NIL;
+  infoton *to_return = NULL_POINTER;
   GRAB_LOCK;
   entity_basket *bask = _table->find(id._entity);
-  if (!bask) return NIL;
+  if (!bask) return NULL_POINTER;
   if (!bask->elements()) {
 #ifdef DEBUG_ENTITY_DATA_BIN
     LOG(astring("tossing empty basket ") + id._entity.mangled_form());
 #endif
     _table->zap(id._entity);
-    return NIL;
+    return NULL_POINTER;
   }
   for (int i = 0; i < bask->elements(); i++) {
     if (bask->get(i)->_id == id) {
       to_return = bask->borrow(i)->_item;  // snag the item.
-      bask->borrow(i)->_item = NIL;  // clear the list's version out.
+      bask->borrow(i)->_item = NULL_POINTER;  // clear the list's version out.
       bask->zap(i, i);  // whack the sanitized element.
       DUMP_STATE;
       if (!bask->elements()) {
@@ -394,7 +393,7 @@ infoton *entity_data_bin::acquire_for_identifier(const octopus_request_id &id)
       return to_return;
     }
   }
-  return NIL;
+  return NULL_POINTER;
 }
 
 bool cleaning_applier(const octopus_entity &key, entity_basket &bask,
@@ -473,7 +472,7 @@ void entity_data_bin::clean_out_deadwood(int decay_interval)
 bool entity_data_bin::get_sizes(const octopus_entity &id, int &items,
     int &bytes)
 {
-//  FUNCDEF("get_sizes");
+  FUNCDEF("get_sizes");
   items = 0;
   bytes = 0;
   GRAB_LOCK;