00001 #ifndef CROMP_TRANSACTION_CLASS 00002 #define CROMP_TRANSACTION_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : cromp_transaction * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * The basic structure passed around the network for CROMP requests and * 00012 * responses. * 00013 * * 00014 ******************************************************************************* 00015 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00016 * redistribute it and/or modify it under the terms of the GNU General Public * 00017 * License as published by the Free Software Foundation; either version 2 of * 00018 * the License or (at your option) any later version. This is online at: * 00019 * http://www.fsf.org/copyleft/gpl.html * 00020 * Please send any updates to: fred@gruntose.com * 00021 \*****************************************************************************/ 00022 00023 #include "dll_cromp.h" 00024 00025 #include <basis/object_base.h> 00026 #include <basis/packable.h> 00027 00028 // forward. 00029 class infoton; 00030 class octopus_request_id; 00031 00033 00034 class CROMP_CLASS_STYLE cromp_transaction 00035 { 00036 public: 00037 virtual ~cromp_transaction(); 00038 IMPLEMENT_CLASS_NAME("cromp_transaction"); 00039 00040 enum outcomes { 00041 OKAY = common::OKAY, 00042 GARBAGE = common::GARBAGE, 00043 PARTIAL = common::PARTIAL, // header is good but not all data is there yet. 00044 00045 DEFINE_OUTCOME(WAY_TOO_SMALL, -41, "The package is too small for even " 00046 "a header"), 00047 DEFINE_OUTCOME(ILLEGAL_LENGTH, -42, "The package claims a length larger " 00048 "than we allow") 00049 }; 00050 static const char *outcome_name(const outcome &to_name); 00051 00052 static void flatten(byte_array &packed_form, const infoton &request, 00053 const octopus_request_id &id); 00054 // encapsulate the "request" with the "id" in a wire-friendly format in the 00055 // "packed_form". this makes the infoton a bit more seaworthy out on the 00056 // network using a recognizable header. 00057 00058 static bool unflatten(byte_array &packed_form, byte_array &still_flat, 00059 octopus_request_id &id); 00060 // re-inflates the infoton from the "packed_form" as far as retrieving 00061 // the original chunk of bytes in "still_flat". the "id" is also unpacked. 00062 00063 static int minimum_flat_size(const octopus_request_id &id); 00064 static int minimum_flat_size(const string_array &classifier, 00065 const octopus_request_id &id); 00066 // returns the amount of packing overhead added by this class given the 00067 // request "id" that will be used. the second method can include the 00068 // "classifier" also, in order to add in overhead from infoton::fast_pack. 00069 // neither of these methods considers the flat size of the associated 00070 // infoton. 00071 00072 static bool resynchronize(byte_array &packed_form); 00073 // chows down on the "packed_form" until we see a header or there's 00074 // nothing left in the array. note that if there's a header already 00075 // present, this will stop immediately. be sure to zap at least one 00076 // byte from the front if there was already a header present. 00077 00078 static outcome peek_header(const byte_array &packed_form, int &length); 00079 // examines the data in "packed_form" and judges whether we think it's 00080 // got a valid transaction there yet or not. the outcome returned is one 00081 // of the peek_outcomes. if the outcome is OKAY or PARTIAL, then 00082 // the operation can be considered successful and the "length" is set to 00083 // the expected size of the "packed_form". however, OKAY is the only 00084 // outcome denoting that the whole package is present. 00085 }; 00086 00087 #endif 00088
1.5.1