feisty meow concerns codebase  2.140
tentacle_helper.h
Go to the documentation of this file.
1 #ifndef TENTACLE_HELPER_CLASS
2 #define TENTACLE_HELPER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : tentacle_helper *
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 "infoton.h"
19 #include "tentacle.h"
20 
21 #include <basis/byte_array.h>
22 #include <basis/outcome.h>
24 
37 namespace octopi {
38 
40 
43 template <class contents>
45  basis::byte_array &packed_form,
46  infoton * &reformed, contents *formal(junk))
47 {
48  contents *inf = new contents;
49  if (!inf->unpack(packed_form)) {
50  WHACK(inf);
51  return tentacle::GARBAGE;
52  }
53  reformed = inf;
54  reformed->set_classifier(classifier);
55  return tentacle::OKAY;
56 }
57 
59 
61 
66 template <class contents>
67 class tentacle_helper : public tentacle
68 {
69 public:
70  tentacle_helper(const structures::string_array &classifier, bool backgrounded,
72  : tentacle(classifier, backgrounded, motivational_rate) {}
73 
74  virtual ~tentacle_helper() {}
76 
79  basis::byte_array &packed_form, infoton * &reformed) {
80  return reconstituter(classifier, packed_form, reformed,
81  (contents *)NULL_POINTER);
82  }
83 
85 
90  virtual basis::outcome consume(infoton &formal(to_chow),
91  const octopus_request_id &formal(item_id), basis::byte_array &transformed)
92  { transformed.reset(); return NO_HANDLER; }
93 
94  virtual void expunge(const octopus_entity &formal(to_remove)) {}
96 };
97 
98 } //namespace.
99 
100 #endif
101 
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
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
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
void set_classifier(const structures::string_array &new_classifier)
sets the infoton's classifier to the "new_classifier".
Definition: infoton.cpp:104
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
provides prefab implementations for parts of the tentacle object.
virtual basis::outcome reconstitute(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed)
this is a simple enough action that it is totally automated.
virtual ~tentacle_helper()
force a virtual destructor.
virtual void expunge(const octopus_entity &formal(to_remove))
no general actions for expunge; they are all class-specific.
virtual basis::outcome consume(infoton &formal(to_chow), const octopus_request_id &formal(item_id), basis::byte_array &transformed)
consume is not really provided here. remember to implement for servers!
tentacle_helper(const structures::string_array &classifier, bool backgrounded, int motivational_rate=tentacle::DEFAULT_RATE)
Manages a service within an octopus by processing certain infotons.
Definition: tentacle.h:36
int motivational_rate() const
returns the background processing rate this was constructed with.
Definition: tentacle.cpp:101
@ 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 formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition: definitions.h:48
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition: functions.h:121
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.