feisty meow concerns codebase 2.140
unhandled_request.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : unhandled_request *
4* Author : Chris Koeritz *
5* *
6*******************************************************************************
7* Copyright (c) 2004-$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 "unhandled_request.h"
16
17using namespace basis;
18using namespace structures;
19
20namespace octopi {
21
23 const string_array &original_classifier, const outcome &reason)
24: infoton(the_classifier()),
25 _original_id(original_id),
26 _original_classifier(original_classifier),
27 _reason(reason)
28{}
29
32
38
40{
41 fill.assign(astring("classifier=") + the_classifier().text_form()
42 + " original_id=" + _original_id.text_form()
43 + a_sprintf(" reason=%d", _reason.value()));
44}
45
46const char *initter[] = { "__Unhandled__", NULL_POINTER };
47
50
51void unhandled_request::pack(byte_array &packed_form) const
52{
53 _original_id.pack(packed_form);
54 _original_classifier.pack(packed_form);
55 attach(packed_form, _reason.value());
56}
57
59{
60 if (!_original_id.unpack(packed_form)) return false;
61 if (!_original_classifier.unpack(packed_form)) return false;
62 int val;
63 if (!detach(packed_form, val)) return false;
64 _reason = outcome(val);
65 return true;
66}
67
68} //namespace.
69
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Defines the base class for all string processing objects in hoople.
Definition base_string.h:28
virtual base_string & assign(const base_string &s)=0
Sets the contents of this string to "s".
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
A clonable object knows how to make copy of itself.
Definition contracts.h:109
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
int value() const
Definition outcome.h:51
int packed_size() const
a convenience function for those packing outcomes.
Definition outcome.h:54
An infoton is an individual request parcel with accompanying information.
Definition infoton.h:32
virtual basis::astring text_form() const
local version just makes text_form() more functional.
Definition infoton.h:108
Identifies requests made on an octopus by users.
int packed_size() const
reports how large the packed id will be.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
basis::astring text_form() const
human readable form of the request.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
Informs the caller that a request type was unknown to the server octopus.
unhandled_request(const octopus_request_id &id=octopus_request_id(), const structures::string_array &original_classifier=structures::string_array(), const basis::outcome &reason=basis::common::NO_HANDLER)
virtual int packed_size() const
reports how large the infoton will be when packed.
octopus_request_id _original_id
the failed request's identifier.
virtual clonable * clone() const
must be provided to allow creation of a copy of this object.
static structures::string_array the_classifier()
the classifier for unknown infotons makes unhandled requests unique.
virtual void pack(basis::byte_array &packed_form) const
stuffs the data in the infoton into the "packed_form".
virtual bool unpack(basis::byte_array &packed_form)
restores an infoton from a packed form.
basis::outcome _reason
the reason why this request was provided.
structures::string_array _original_classifier
the original name of the request.
An array of strings with some additional helpful methods.
virtual void pack(basis::byte_array &packed_form) const
Packs this string array into the "packed_form" byte array.
virtual bool unpack(basis::byte_array &packed_form)
Unpacks a string array from the "packed_form" byte array.
virtual int packed_size() const
Returns the number of bytes this string array would consume if packed.
#define NULL_POINTER
The value representing a pointer to nothing.
Definition definitions.h:32
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
Definition astring.cpp:1018
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
Definition astring.cpp:1026
const char * initter[]
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55