first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / octopi / library / octopus / unhandled_request.cpp
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
17 using namespace basis;
18 using namespace structures;
19
20 namespace octopi {
21
22 unhandled_request::unhandled_request(const octopus_request_id &original_id,
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
30 clonable *unhandled_request::clone() const 
31 { return new unhandled_request(_original_id, _original_classifier, _reason); }
32
33 int unhandled_request::packed_size() const
34 {
35   return _original_id.packed_size() + _original_classifier.packed_size()
36       + _reason.packed_size();
37 }
38
39 void unhandled_request::text_form(basis::base_string &fill) const
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
46 const char *initter[] = { "__Unhandled__", NIL };
47
48 string_array unhandled_request::the_classifier()
49 { return string_array(1, initter); }
50
51 void 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
58 bool unhandled_request::unpack(byte_array &packed_form) 
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