feisty meow concerns codebase  2.140
tentacle.h
Go to the documentation of this file.
1 #ifndef TENTACLE_CLASS
2 #define TENTACLE_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : tentacle *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2002-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/byte_array.h>
19 #include <basis/mutex.h>
21 
22 namespace octopi {
23 
24 // forward.
25 class entity_data_bin;
26 class infoton;
27 class octopus;
28 class octopus_entity;
29 class octopus_request_id;
30 class pod_motivator;
31 class queueton;
32 
34 
35 class tentacle : public virtual basis::root_object
36 {
37 public:
38  tentacle(const structures::string_array &group_name, bool backgrounded,
41 
47  virtual ~tentacle();
48 
49  enum constants { DEFAULT_RATE = 40 };
50 
51  DEFINE_CLASS_NAME("tentacle");
52 
53  const structures::string_array &group() const;
55 
58  bool backgrounding() const { return _backgrounded; }
60 
61  int motivational_rate() const;
63 
64  enum outcomes {
65  OKAY = basis::common::OKAY,
66  NOT_FOUND = basis::common::NOT_FOUND,
67  ALREADY_EXISTS = basis::common::EXISTING,
68  BAD_INPUT = basis::common::BAD_INPUT,
69  NO_SPACE = basis::common::NO_SPACE,
70  GARBAGE = basis::common::GARBAGE,
71  DISALLOWED = basis::common::DISALLOWED,
72 
73  NO_HANDLER = basis::common::NO_HANDLER,
74  PARTIAL = basis::common::PARTIAL,
75  ENCRYPTION_MISMATCH = basis::common::ENCRYPTION_MISMATCH
77  };
78 
79  static const char *outcome_name(const basis::outcome &to_name);
81 
83 
84  // functions that must be provided by derived tentacles.
85 
87  basis::byte_array &packed_form, infoton * &reformed) = 0;
89 
95  virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id,
96  basis::byte_array &transformed) = 0;
98 
123  virtual void expunge(const octopus_entity &to_remove) = 0;
125 
131 
132  basis::outcome enqueue(infoton *to_chow, const octopus_request_id &item_id);
134 
142 
147  bool store_product(infoton *product, const octopus_request_id &original_id);
149 
157 
158  // support that is for internal use only.
159 
160  void attach_storage(entity_data_bin &storage);
162 
165  void detach_storage();
169 
170  void propel_arm();
172 
173 private:
174  structures::string_array *_group;
175  queueton *_pending;
176  basis::mutex *_input_guard;
177  pod_motivator *_action;
178  entity_data_bin *_products;
179  bool _backgrounded;
180 
181  // not permitted.
182  tentacle(const tentacle &);
183  tentacle &operator =(const tentacle &);
184 };
185 
186 } //namespace.
187 
188 #endif
189 
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
Stores a set of infotons grouped by the entity that owns them.
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
Provides a way of identifying users of an octopus object.
Definition: entity_defs.h:35
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
Manages a service within an octopus by processing certain infotons.
Definition: tentacle.h:36
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
virtual ~tentacle()
Definition: tentacle.cpp:87
virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id, basis::byte_array &transformed)=0
this is the main function that processes infotons for this tentacle.
basis::outcome enqueue(infoton *to_chow, const octopus_request_id &item_id)
holds onto infotons coming from the octopus for backgrounding.
Definition: tentacle.cpp:131
bool backgrounding() const
reports on whether this tentacle supports background operation or not.
Definition: tentacle.h:58
const structures::string_array & group() const
returns the name of the group that this tentacle services.
Definition: tentacle.cpp:96
virtual basis::outcome reconstitute(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed)=0
regenerates an infoton from its packed form.
static const char * outcome_name(const basis::outcome &to_name)
returns the textual form of the outcome "to_name".
Definition: tentacle.cpp:98
void detach_storage()
unhooks the storage bin from this tentacle.
Definition: tentacle.cpp:112
DEFINE_CLASS_NAME("tentacle")
virtual void expunge(const octopus_entity &to_remove)=0
called to remove traces of the entity "to_remove".
int motivational_rate() const
returns the background processing rate this was constructed with.
Definition: tentacle.cpp:101
@ PARTIAL
processing of request is partially done.
Definition: tentacle.h:74
@ ENCRYPTION_MISMATCH
there is a disconnect regarding encryption.
Definition: tentacle.h:75
@ NO_HANDLER
no handler for that type of infoton.
Definition: tentacle.h:73
void attach_storage(entity_data_bin &storage)
used when a tentacle is being integrated with an octopus.
Definition: tentacle.cpp:106
infoton * next_request(octopus_request_id &item_id)
pops out the next queued request for processing.
Definition: tentacle.cpp:158
entity_data_bin * get_storage()
returns the current pointer, which might be nil.
Definition: tentacle.cpp:104
void propel_arm()
invoked by our thread to cause requests to be processed.
Definition: tentacle.cpp:170
tentacle(const structures::string_array &group_name, bool backgrounded, int motivational_rate=tentacle::DEFAULT_RATE)
constructs a tentacle that handles infotons with the "group_name".
Definition: tentacle.cpp:73
An array of strings with some additional helpful methods.
Definition: string_array.h:32