Sirikata
libspace/plugins/craq/craq_oseg/asyncUtil.hpp
Go to the documentation of this file.
00001 /*  Sirikata
00002  *  asyncUtil.hpp
00003  *
00004  *  Copyright (c) 2010, Behram Mistree
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions are
00009  *  met:
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *  * Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in
00014  *    the documentation and/or other materials provided with the
00015  *    distribution.
00016  *  * Neither the name of Sirikata nor the names of its contributors may
00017  *    be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00021  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00022  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00023  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00024  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef __ASYNC_UTIL_HPP__
00034 #define __ASYNC_UTIL_HPP__
00035 
00036 #include <string>
00037 #include <sirikata/space/OSegLookupTraceToken.hpp>
00038 #include "CraqEntry.hpp"
00039 namespace Sirikata
00040 {
00041 
00042 const int CRAQ_DATA_RESPONSE_SIZE = 70;
00043 typedef char CraqDataResponseBuffer [CRAQ_DATA_RESPONSE_SIZE];
00044 
00045 
00046   //multi-usef change
00047   //const int CRAQ_DATA_KEY_SIZE = 33;
00048   //typedef char CraqDataKey [CRAQ_DATA_KEY_SIZE];
00049   const int CRAQ_DATA_KEY_SIZE = 34;
00050   typedef char CraqDataKey [CRAQ_DATA_KEY_SIZE];
00051 
00052 const char CRAQ_DATA_KEY_QUERY_PREFIX[]  = "get ";
00053 const char CRAQ_DATA_KEY_QUERY_SUFFIX[] = "\r\n";
00054 const int  CRAQ_DATA_PREFIX_SIZE          = 4;
00055 const int  CRAQ_DATA_SUFFIX_SIZE          = 2;
00056 const int CRAQ_DATA_KEY_QUERY_SIZE       = CRAQ_DATA_KEY_SIZE + CRAQ_DATA_PREFIX_SIZE + CRAQ_DATA_SUFFIX_SIZE;
00057 typedef char CraqDataKeyQuery[CRAQ_DATA_KEY_QUERY_SIZE];  //this is what actually goes out to the router.
00058 
00059 
00060 
00061 const char CRAQ_DATA_SET_PREFIX[]       = "set ";
00062 const char CRAQ_DATA_SET_END_LINE[]     = "\r\n";
00063 const int  CRAQ_DATA_SET_PREFIX_SIZE    =      4;
00064 const int  CRAQ_DATA_SET_END_LINE_SIZE  =      2;
00065 
00066 
00067 
00068 const char CRAQ_DATA_TO_SET_SIZE[]      = " 12";
00069 const int  CRAQ_DATA_TO_SET_SIZE_SIZE   =     3; //There are 3 digits in the above.
00070 
00071 const int  CRAQ_TO_SET_SUFFIX_SIZE      =     2;
00072 const char CRAQ_TO_SET_SUFFIX[]         =  "ND";
00073 const int  CRAQ_DATA_VALUE_SIZE         =    12;
00074 typedef char CraqDataValue [CRAQ_DATA_VALUE_SIZE];
00075 
00076 
00077 const char CRAQ_GET_RESP[]              =      "VALUE12";
00078 const int  CRAQ_GET_RESP_SIZE           =              7;
00079 
00080   //const int CRAQ_THREAD_POOL_CONNECTIONS  =             10;
00081 
00082 
00083 const int CRAQ_DATA_SET_SIZE       = CRAQ_DATA_SET_PREFIX_SIZE + CRAQ_DATA_KEY_SIZE + CRAQ_DATA_TO_SET_SIZE_SIZE + CRAQ_DATA_SET_END_LINE_SIZE + CRAQ_DATA_VALUE_SIZE + CRAQ_DATA_SET_END_LINE_SIZE +1;
00084 
00085 typedef char CraqDataSetQuery[CRAQ_DATA_SET_SIZE];  //this is what actually goes out to the router.
00086 
00087 
00088 const char CRAQ_NOT_FOUND_RESP[] = "NOT_FOUND";
00089 
00090 
00091 const int CRAQ_DATA_GET_RESP_SIZE         = 52;
00092 typedef char CraqDataGetResp[CRAQ_DATA_GET_RESP_SIZE];
00093 
00094 
00095 
00096   //const int CRAQ_NUM_CONNECTIONS            = 10;
00097   const int CRAQ_NUM_CONNECTIONS            = 40;
00098 
00099 struct CraqObjectID
00100 {
00101   CraqDataKey cdk;
00102 };
00103 
00104 
00105 struct CraqOperationResult
00106 {
00107   CraqEntry servID;
00108   CraqDataKey objID;
00109   int trackedMessage; //id assigned to track
00110   bool tracking;  //are we tracking this message
00111   bool succeeded;
00112   enum GetOrSet {GET, SET};
00113   GetOrSet whichOperation;
00114   CraqOperationResult(const CraqEntry& sID,const CraqDataKey& obj_id, const int& tm, const bool& suc, const GetOrSet& gos,const  bool& track_or_not);
00115   CraqOperationResult(const CraqEntry& sID,const CraqDataKey& obj_id, const int& tm, const bool& suc, const GetOrSet& gos,const  bool& track_or_not, OSegLookupTraceToken* ttoken);
00116   std::string idToString();
00117   OSegLookupTraceToken* traceToken;
00118 };
00119 
00120 struct CraqInitializeArgs
00121 {
00122   std::string ipAdd;
00123   std::string port;
00124 };
00125 struct CraqDataSetGet
00126 {
00127   CraqDataKey dataKey;
00128   CraqEntry dataKeyValue;
00129   bool trackMessage;
00130   int trackingID;
00131   enum TypeMessage {GET,SET};
00132   TypeMessage messageType;
00133   CraqDataSetGet(const std::string& dKey, const CraqEntry& dKeyValue, const bool& tMessage, const TypeMessage& message_type);
00134   CraqDataSetGet(const CraqDataKey& dKey, const CraqEntry& dKeyValue, const bool& tMessage, const TypeMessage& message_type);
00135 };
00136 
00137 
00138 }//end namespace
00139 
00140 #endif