FountainMessage.h

Go to the documentation of this file.
00001 /* ex: set tabstop=4 expandtab: */
00002 /*                                                                                                                      */
00003 /*  (c) 2004-2006 Iowa State University                                         */
00004 /*      see the LICENSE file in the top level directory         */
00005 /*                                                                                                                      */
00006 /* $Header: /afs/scl/project/cvsroot/fountain/source/common/FountainMessage.h,v 1.27 2006/03/05 22:05:16 samm Exp $ */
00015 #ifndef FOUNTAIN_MESSAGE_H__
00016 #define FOUNTAIN_MESSAGE_H__
00017 
00018 //forward class declarations
00019 class FountainParseMessage;
00020 class NodeID;
00021 
00022 #include "define.h"
00023 #include "Enforce.h"
00024 #include "LokiInclude.h"
00025 #include <bamboo/BaseMsg.h>
00026 #include <bamboo/XML.h>
00027 #include <cstdlib>
00028 #include <vector>
00029 #include <string>
00030 #include <sys/time.h>
00031 
00032 //forward declaration
00033 class FountainParseMessage;
00034 class FountainMessage;
00035 
00041 typedef Loki::SmartPtr<const FountainParseMessage> ConstParseMsgPtr;
00042 
00048 typedef Loki::SmartPtr<FountainMessage> FountainMessagePtr;
00049 
00061 typedef Loki::SmartPtr<BambooLib::XMLElementList, Loki::RefCounted, Loki::DisallowConversion, Loki::RejectNullStrict> XMLElementListPtr;
00062 
00083 class FountainMessage : public BambooLib::BuildMsg {
00084     public:
00091                 enum MessageAction {
00092                         invalidAction=0,
00093                         join,
00094                         newParent,
00095                         syncMsg,
00096                         pulse,
00097                         admin,
00098                         pingPong,
00099                         trace,
00100                         bomb,
00101                         joinAsServer,
00102                         Query,
00103                         lostParent,
00104                         lostChild,
00105                         wakeup,
00106                         Number_Message_Actions
00107                 };
00108         
00112         virtual ~FountainMessage() = 0;
00113 
00120         void buildStandardError(bool status=true, FountainErrorCode code=generalSuccess, const char* msg=NULL);
00121                 
00125                 void buildStandardError(bool status, FountainErrorCode code, const std::string& msg) { buildStandardError(status, code, msg.c_str()); };
00126                 
00130                 void buildStandardSuccess(const std::string& msg = std::string()) { return buildStandardError(true, generalSuccess, msg); }
00131 
00136                 BambooLib::XMLElement* getDataElement() const { return dataElement; }
00137                 
00142                 static const char* fountain_convert(FountainMessage::MessageAction m);
00143                 
00151                 static bool fountain_convert(const char* s, FountainMessage::MessageAction& a);
00152                 
00153     protected:
00159                 FountainMessage(Loki::Int2Type<BambooLib::requestElement>, MessageAction a) : BambooLib::BuildMsg(sss_convert(BambooLib::envelopeElement)), action_(a) { create(BambooLib::requestElement); }
00160                 
00166                 FountainMessage(Loki::Int2Type<BambooLib::responseElement>, MessageAction a) : BambooLib::BuildMsg(sss_convert(BambooLib::envelopeElement)), action_(a) { create(BambooLib::responseElement); }
00167                 
00171         MessageAction action_;
00172         
00173     private:
00184                 void create(BambooLib::SSS_Element_type type);
00185                 
00189                 FountainMessage(const FountainMessage& rhs);
00190                 
00194         const FountainMessage& operator=(const FountainMessage& rhs);
00195 };
00196 
00224 class FountainParseMessage {
00225         private:
00235                 typedef Loki::SmartPtr<const BambooLib::ParseMsg, Loki::NoCopy, Loki::AllowConversion, Loki::RejectNullStrict> BambooParseMsg;
00236                 
00240                 BambooParseMsg msg_;
00241         
00242         public:
00247                 FountainParseMessage(const BambooLib::ParseMsg* msg) : msg_(msg) {}
00248         
00252                 ~FountainParseMessage() {}
00253                 
00257                 //operator BambooParseMsg::PointerType() const { return msg_; }
00258                 
00262                 BambooParseMsg::PointerType getParseMsg() const { return msg_; }
00263         
00269                 FountainMessage::MessageAction getAction() const;
00270         
00274                 bool getStatus() const { return msg_->getStatus(); }
00275                 
00279                 BambooLib::SSS_Element_type getMessageType() const { return msg_->getMessageType(); }
00280                 
00284                 BambooLib::XMLElement* getRoot() const { return msg_->getRoot(); }
00285                 
00289                 const char* getActor() const { return msg_->getActor(); }
00290                 
00294                 BambooLib::XMLElement* getDataElement() const { return msg_->getDataElement(); }
00295                 
00300                 const char* getDataElementValue(const char* value) const { return msg_->getDataElementValue(value); }
00301                 
00306                 const char* getResponseMessage() const { return msg_->getResponseMessage(); }
00307                 
00312                 const char* getSource() const;
00313                 
00318                 const char* getDestination() const;
00319                 
00325                 FountainErrorCode getErrorCode() const;
00326                 
00330                 friend std::ostream& operator<<(std::ostream& output, const FountainParseMessage& rhs);
00331                 
00332         private:
00336                 FountainParseMessage(const FountainParseMessage& rhs);
00337                 
00341                 FountainParseMessage& operator=(const FountainParseMessage& rhs);
00342 };
00343 
00344 
00345 #endif
00346 

Generated on Wed Mar 8 14:43:31 2006 for Fountain by  doxygen 1.4.6