1 #ifndef ENTITY_DEFINITIONS_GROUP
2 #define ENTITY_DEFINITIONS_GROUP
4 /*****************************************************************************\
6 * Name : various definitions for octopus *
7 * Author : Chris Koeritz *
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 \*****************************************************************************/
20 #include <basis/byte_array.h>
21 #include <basis/astring.h>
22 #include <structures/set.h>
23 #include <structures/amorph.h>
24 #include <structures/unique_id.h>
25 #include <timely/time_stamp.h>
29 //! Provides a way of identifying users of an octopus object.
31 NOTE: this is a heavy-weight header intended for forward declaration.
34 class octopus_entity : public virtual basis::packable, public virtual basis::text_formable
37 octopus_entity(); //!< blank constructor.
39 octopus_entity(const basis::astring &hostname, int process_id, int sequencer,
41 //!< constructor taking all the available parameters for an entity.
42 /*!< produces an id in the proper format given all the components. note
43 that the hostname must be some fully qualified name for the host, such
44 that it is as unique as you want names within the system to be. */
46 octopus_entity(const octopus_entity &to_copy);
50 octopus_entity &operator = (const octopus_entity &to_copy);
52 DEFINE_CLASS_NAME("octopus_entity");
55 //!< true if the entity is blank, as constructed by default constructor.
57 // comparison operators.
58 bool operator == (const octopus_entity &that) const;
60 const basis::astring &hostname() const; //!< returns the hostname portion of the id.
61 int process_id() const; //!< returns the process number in the id.
62 int sequencer() const; //!< returns the sequencing number from the id.
63 int add_in() const; //!< returns the random add-in from the id.
65 void hostname(const basis::astring &new_host); //!< set the host.
66 void process_id(int id); //!< set the process id.
67 void sequencer(int seq); //!< set the sequencer value.
68 void add_in(int add); //!< set the add-in value.
70 basis::astring mangled_form() const;
71 //!< returns the combined string form of the identifier.
73 basis::astring text_form() const;
74 //!< returns a readable form of the identifier.
76 virtual void text_form(basis::base_string &to_fill) const {
77 to_fill.assign(text_form());
80 basis::astring to_text() const { return mangled_form(); }
81 //!< conversion to text format for display.
82 static octopus_entity from_text(const basis::astring &to_convert);
83 //!< conversion from text format, parsing parameters out.
85 static void breakout(const basis::astring &mangled_form, basis::astring &hostname,
86 int &process_id, int &sequencer, int &add_in);
87 //!< takes a "mangled_form" of an entity id and retrieves the components.
89 int packed_size() const;
90 //!< reports how large the packed entity will be.
92 virtual void pack(basis::byte_array &packed_form) const;
93 virtual bool unpack(basis::byte_array &packed_form);
96 basis::astring *_hostname;
104 //! Identifies requests made on an octopus by users.
106 Uniquely identifies a request passed to an octopus server given that
107 the number of requests from one entity can be contained within the range
108 of signed integers. if the requests come fast enough for the request
109 numbers to wrap around, and if the requests can remain outstanding for a
110 really long time, it may be wise to create a new login.
113 class octopus_request_id : public virtual basis::packable
116 octopus_entity _entity; //!< the entity.
117 int _request_num; //!< the item number from the entity.
119 octopus_request_id() : _entity(), _request_num(0) {}
121 octopus_request_id(const octopus_entity &entity, int request_num)
122 : _entity(entity), _request_num(request_num) {}
124 static octopus_request_id randomized_id();
125 //!< provides a pre-randomized request id.
126 /*!< this should only be used for the very first request made to an
127 octopus, in order to obtain a valid identity. */
129 bool operator == (const octopus_request_id &that) const
130 { return (_entity == that._entity)
131 && (_request_num == that._request_num); }
134 //!< returns true if this is a blank id (as constructed by default ctor).
136 int packed_size() const;
137 //!< reports how large the packed id will be.
139 basis::astring mangled_form() const; //!< similar to entity id.
141 basis::astring text_form() const; //!< human readable form of the request.
143 basis::astring to_text() const { return mangled_form(); }
144 static octopus_request_id from_text(const basis::astring &to_convert);
146 virtual void pack(basis::byte_array &packed_form) const;
147 virtual bool unpack(basis::byte_array &packed_form);
150 //! a collection of unique request ids.
151 class octopus_request_id_set : public structures::set<octopus_request_id>
154 octopus_request_id_set() {}
156 octopus_request_id_set(const structures::set<octopus_request_id> &orig)
157 : structures::set<octopus_request_id>(orig) {}
162 //! implements a list of waiting infotons.
163 /*! the actual infoton plus its request id are stored. */
165 class infoton_id_pair : public virtual basis::root_object
169 octopus_request_id _id;
171 infoton_id_pair(infoton *data, const octopus_request_id &id)
172 : _data(data), _id(id) {}
176 _data = NULL_POINTER;
180 //! a list of pending requests and who made them.
181 class infoton_list : public structures::amorph<infoton_id_pair> {};