Sirikata
|
00001 00002 #ifndef __SIRIKATA_JS_JSOBJECTUTILS_HPP__ 00003 #define __SIRIKATA_JS_JSOBJECTUTILS_HPP__ 00004 00005 #include <v8.h> 00006 #include <sirikata/core/util/Platform.hpp> 00007 #include "../JSObjectStructs/JSPositionListener.hpp" 00008 00009 namespace Sirikata{ 00010 namespace JS{ 00011 00012 class JSWatchable; 00013 00014 00015 JSPositionListener* decodeJSPosListener(v8::Handle<v8::Value> toDecode,String& errorMessage); 00016 bool decodeString(v8::Handle<v8::Value> toDecode, String& decodedValue, String& errorMessage); 00017 bool decodeBool(v8::Handle<v8::Value> toDecode, bool& decodedValue, String& errorMessage); 00018 bool decodeSporef(v8::Handle<v8::Value> toDecode, SpaceObjectReference& sporef, String& errorMessage); 00019 bool decodeSpaceID(v8::Handle<v8::Value> toDecode,SpaceID& space, String& errorMessage); 00020 bool decodeObjectReference(v8::Handle<v8::Value> toDecode, ObjectReference& oref, String& errorMessage); 00021 bool decodeUint64FromString(v8::Handle<v8::Value> toDecode,uint64& decodedInt, String& errorMessage); 00022 bool decodeTimedMotionVector(v8::Handle<v8::Value>toDecodePos, v8::Handle<v8::Value>toDecodeVel,v8::Handle<v8::Value>toDecodeTimeAsString, TimedMotionVector3f& toDecodeTo, String& errorMessage); 00023 bool decodeTimedMotionQuat(v8::Handle<v8::Value> orientationQuat,v8::Handle<v8::Value> orientationVelQuat,v8::Handle<v8::Value> toDecodeTimeAsString, TimedMotionQuaternion& toDecodeTo, String& errMsg); 00024 bool decodeBoundingSphere3f(v8::Handle<v8::Value> toDecodeCenterVec, v8::Handle<v8::Value> toDecodeRadius, BoundingSphere3f& toDecodeTo, String& errMsg); 00025 bool decodeInt64(v8::Handle<v8::Value> toDecode, int64& toDecodeTo, String& errMsg); 00026 bool decodeUint32(v8::Handle<v8::Value> toDecode, uint32& toDecodeTo, String& errMsg); 00027 bool decodeSolidAngle(v8::Handle<v8::Value> toDecode, SolidAngle& toDecodeTo, String& errMsg); 00028 bool decodeDouble(v8::Handle<v8::Value> toDecode, double& toDecodeTo, String& errMsg); 00029 bool decodeTimeFromString (v8::Handle<v8::Value> toDecode, Time& toDecodeTo, String& errorMessage); 00030 00031 void debug_checkCurrentContextX(v8::Handle<v8::Context> ctx, String additionalMessage); 00032 void printAllPropertyNames(v8::Handle<v8::Object> objToPrint); 00033 00034 String uint16StrToStr(v8::Handle<v8::String> toDeserialize); 00035 v8::Handle<v8::Value> strToUint16Str(const String& toSerialize); 00036 00037 00038 #define V8_EXCEPTION_STRING(stringErrMsg)\ 00039 return v8::ThrowException(v8::Exception::Error(v8::String::New(stringErrMsg.c_str(),stringErrMsg.length()))); 00040 00041 #define V8_EXCEPTION_CSTR(cstrErrMsg)\ 00042 return v8::ThrowException(v8::Exception::Error(v8::String::New(cstrErrMsg))); 00043 00044 00045 #define INLINE_TIME_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo)\ 00046 Time whereWriteTo; \ 00047 { \ 00048 String _errMsg = "In " #whereError " cannot convert arg " #whichArg " to Time"; \ 00049 if (!decodeTimeFromString(toConvert,whereWriteTo,_errMsg)) \ 00050 V8_EXCEPTION_STRING(_errMsg); \ 00051 } 00052 00053 #define INLINE_DOUBLE_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo)\ 00054 double whereWriteTo; \ 00055 { \ 00056 String _errMsg = "In " #whereError " cannot convert arg " #whichArg " to double"; \ 00057 if (!decodeDouble(toConvert,whereWriteTo,_errMsg)) \ 00058 V8_EXCEPTION_STRING(_errMsg); \ 00059 } 00060 00061 #define INLINE_INTEGER_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo)\ 00062 int64 whereWriteTo; \ 00063 { \ 00064 String _errMsg = "In " #whereError " cannot convert arg " #whichArg " to integer"; \ 00065 if (!decodeInt64(toConvert,whereWriteTo,_errMsg)) \ 00066 V8_EXCEPTION_STRING(_errMsg); \ 00067 } 00068 00069 00070 #define INLINE_SPACEID_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo)\ 00071 SpaceID whereWriteTo; \ 00072 { \ 00073 String _errMsg = "In " #whereError "cannot convert arg " #whichArg " to space id"; \ 00074 if (!decodeSpaceID(toConvert,whereWriteTo,_errMsg)) \ 00075 return v8::ThrowException(v8::Exception::Error(v8::String::New(_errMsg.c_str(), _errMsg.length()))); \ 00076 } 00077 00078 00079 00080 #define INLINE_OBJID_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo)\ 00081 ObjectReference whereWriteTo; \ 00082 { \ 00083 String _errMsg = "In " #whereError "cannot convert arg " #whichArg " to object reference"; \ 00084 if (!decodeObjectReference(toConvert,whereWriteTo,_errMsg)) \ 00085 return v8::ThrowException(v8::Exception::Error(v8::String::New(_errMsg.c_str(), _errMsg.length()))); \ 00086 } 00087 00088 00089 00090 00091 #define INLINE_SA_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo) \ 00092 SolidAngle whereWriteTo; \ 00093 { \ 00094 String _errMsg = "In " #whereError "cannot convert arg " #whichArg " to solid angle"; \ 00095 if (!decodeSolidAngle(toConvert,whereWriteTo,_errMsg)) \ 00096 return v8::ThrowException(v8::Exception::Error(v8::String::New(_errMsg.c_str(), _errMsg.length()))); \ 00097 } 00098 00105 #define INLINE_DECODE_UINT_32(toConvert,whereWriteTo) \ 00106 uint32 whereWriteTo; \ 00107 { \ 00108 String _errMsg; \ 00109 if (! decodeUint32(toConvert,whereWriteTo,_errMsg)) \ 00110 JSLOG(error, "error. cannot decode the uint32 in INLINE_DECODE_UINT_32"); \ 00111 } 00112 00113 00114 #define INLINE_DECODE_UINT_32_ERROR(toConvert,whereError,whichArg,whereWriteTo) \ 00115 uint32 whereWriteTo; \ 00116 { \ 00117 String _errMsg = "In " #whereError "cannot convert " #whichArg " to uint32";\ 00118 if (! decodeUint32(toConvert,whereWriteTo,_errMsg)) \ 00119 return v8::ThrowException(v8::Exception::Error(v8::String::New(_errMsg.c_str(), _errMsg.length()))); \ 00120 } 00121 00122 00123 00124 00135 #define INLINE_STR_CONV_ERROR(toConvert,whereError,whichArg,whereWriteTo) \ 00136 String whereWriteTo; \ 00137 { \ 00138 String _errMsg = "In " #whereError "cannot convert arg " #whichArg " to string"; \ 00139 if (!decodeString(toConvert,whereWriteTo,_errMsg)) \ 00140 return v8::ThrowException(v8::Exception::Error(v8::String::New(_errMsg.c_str(), _errMsg.length()))); \ 00141 } 00142 00150 #define INLINE_STR_CONV(toConvert,whereWriteTo,defaultArg) \ 00151 String whereWriteTo; \ 00152 { \ 00153 String _errMsg; \ 00154 if (!decodeString(toConvert,whereWriteTo,_errMsg)) \ 00155 { \ 00156 JSLOG(error,"error. cannot decode the string value in INLINE_STR_CONV"); \ 00157 whereWriteTo = defaultArg; \ 00158 } \ 00159 } 00160 00161 00162 } //end namespace js 00163 } //end namespace sirikata 00164 00165 #endif