feisty meow concerns codebase  2.140
identity_tentacle.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : identity_tentacle *
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 "identity_tentacle.h"
16 #include "identity_infoton.h"
17 #include "octopus.h"
18 
19 #include <structures/string_hash.h>
20 #include <timely/time_stamp.h>
21 
22 using namespace basis;
23 using namespace structures;
24 using namespace timely;
25 
26 namespace octopi {
27 
28 #undef LOG
29 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
30 
31 //#define DEBUG_IDENTITY_TENTACLE
32  // uncomment for debugging version.
33 
35 
36 identity_tentacle::identity_tentacle(octopus &parent)
37 : tentacle_helper<identity_infoton>(identity_infoton::identity_classifier(),
38  false),
39  _parent(parent)
40 {}
41 
43 
45  byte_array &packed_form, infoton * &reformed)
46 {
47  if (classifier != identity_infoton::identity_classifier())
48  return NO_HANDLER;
49 
50  return reconstituter(classifier, packed_form, reformed,
52 }
53 
55  const octopus_request_id &item_id, byte_array &transformed)
56 {
57 #ifdef DEBUG_IDENTITY_TENTACLE
58  FUNCDEF("consume");
59 #endif
60  transformed.reset();
61  identity_infoton *inf = dynamic_cast<identity_infoton *>(&to_chow);
62  if (!inf) {
63  // if the infoton doesn't cast, then it is not for us. we need to vet
64  // that the identity looks pretty much okay.
65 
66 //hmmm: check host?
67 // that would imply that all users of octopi have correctly identified
68 // themselves. this is not currently the case. we need a way to
69 // automate that step for a user of an octopus?
70 bool uhhh = true;
71 
72  if (uhhh) {
73  // this infoton's entity was allowed, so we call it partially processed.
74  return PARTIAL;
75  }
76 #ifdef DEBUG_IDENTITY_TENTACLE
77  LOG(astring("denying infoton ") + item_id.mangled_form());
78 #endif
79  // the infoton's identity is invalid; it needs to be dropped.
80  return DISALLOWED;
81  }
82 
83 #ifdef DEBUG_IDENTITY_TENTACLE
84  LOG(astring("old name, storing under: ") + item_id.mangled_form());
85 #endif
86 
87  // this is definitely for an identity request now.
88  inf->_new_name = _parent.issue_identity();
89 
90 #ifdef DEBUG_IDENTITY_TENTACLE
91  LOG(astring("new name: ") + inf->_new_name.mangled_form());
92 #endif
93 
94  if (!store_product(dynamic_cast<infoton *>(inf->clone()), item_id))
95  return NO_SPACE;
96  return OKAY;
97 }
98 
99 } //namespace.
100 
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
Definition: array.h:349
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
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
Encapsulates just the action of identifying an octopus user.
virtual clonable * clone() const
must be provided to allow creation of a copy of this object.
static const structures::string_array & identity_classifier()
returns the classifier for this type of infoton.
virtual basis::outcome reconstitute(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed)
reinflates an infoton given that we know the type in "classifier".
virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id, basis::byte_array &transformed)
chews on the "to_chow" infoton to perform the requested action.
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
basis::astring mangled_form() const
returns the combined string form of the identifier.
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
basis::astring mangled_form() const
similar to entity id.
Octopus is a design pattern for generalized request processing systems.
Definition: octopus.h:47
octopus_entity issue_identity()
creates an entity identifier that is unique for this octopus.
Definition: octopus.cpp:527
provides prefab implementations for parts of the tentacle object.
bool store_product(infoton *product, const octopus_request_id &original_id)
used by tentacles to store the objects they produce from infotons.
Definition: tentacle.cpp:118
@ PARTIAL
processing of request is partially done.
Definition: tentacle.h:74
@ NO_HANDLER
no handler for that type of infoton.
Definition: tentacle.h:73
An array of strings with some additional helpful methods.
Definition: string_array.h:32
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
#define LOG(s)
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
basis::outcome reconstituter(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed, contents *formal(junk))
< reconstituter should work for most infotons to restore flattened infotons.
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#include <time.h>
Definition: earth_time.cpp:37