AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
00001 // 00002 // 00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine 00004 // 00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk 00006 // 00007 // For updates, tutorials and more details check out www.appeasymobile.com 00008 // 00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin. 00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support 00011 // 00012 // 00013 00014 #if !defined(_CZ_REMOTEREQ_H_) 00015 #define _CZ_REMOTEREQ_H_ 00016 00017 00018 #include "CzUtil.h" 00019 #include "CzXoml.h" 00020 #include "CzXomlVariables.h" 00021 #include "CzHttp.h" 00022 #include "CzActions.h" 00023 #include "CzEvents.h" 00024 00025 /** 00026 @addtogroup Comms 00027 @{ 00028 */ 00029 00030 /** 00031 @class CzRemoteReq 00032 00033 @brief CzRemmoteReq - A remote request. 00034 00035 XOML provides many ways of communicating with external data that is located on a web server / web site. Files, images, audio and fonts can for example reside 00036 outside the app on some web site and can be loaded on demand by the XOML app. This is a very easy to use automated system that provides very powerful control 00037 over what resources you ship with your apps and which you can host on a server and change at any time. 00038 00039 However, its often useful to be able to communicate with a web service or web service, such as send information about the user or the app. For example, your 00040 app may store its users data on the server in a database. XOML offers the ability to use both HTTP POST and GET to send and retrieve data to and from a web server. 00041 00042 Heres a short example: 00043 00044 @par XOML Example: 00045 @code 00046 <RemoteReq Name="Request1" URL="http://www.mywebservice.com" Data="name=Mat" OnResponse="GotData" OnError="Error" Variable="ReqVar1"> 00047 <Header Name="Content-Type" Value="application/x-www-form-urlencoded" /> 00048 </RemoteReq> 00049 @endcode 00050 00051 This example creates a remote request definition that calls mywebservice.com and passes the data “name=Mat”. The inner header tag sets the Content-Type header. 00052 The server will later send a response which is written into the variable ReqVar1 and calls the GotData actions list allowing you to perform actions when the 00053 data I received. If an error occurs then Error actions list will be called instead. 00054 00055 Note that a RemoteReq is not automatically sent when it is created. You need to actually call the request from an action or program command, e.g.: 00056 00057 @code 00058 <Actions Name="GetData"> 00059 <Action Method="RemoteReq" P1="Request1" /> 00060 </Actions> 00061 00062 <Program Name="Program1" AutoRun="true"> 00063 <Command Method="remote_req" P1="Request1" /> 00064 </Program> 00065 @endcode 00066 00067 A request will remain in memory for as long as the RemoteReq resource is available. A RemoteReq can be re-used. 00068 00069 */ 00070 00071 class CzRemoteReq : public IzXomlResource 00072 { 00073 public: 00074 // Properties 00075 protected: 00076 CzEventManager* EventsManager; // List of events 00077 CzXomlVariable* Variable; // Variable that is will receieve the response data 00078 public: 00079 // Properties end 00080 void setUrl(const char* url) { Request.setURI(url); } 00081 const CzString& getUrl() const { return Request.getURI(); } 00082 CzEventManager* getEventsManager() { return EventsManager; } 00083 void setPost(bool post) { if (post) Request.setPOST(); else Request.setGET(); } 00084 bool isPost() const { return Request.isPOST(); } 00085 void setVariable(const char* variable_name); 00086 void setVariable(CzXomlVariable* var) { Variable = var; } 00087 CzXomlVariable* getVariable() { return Variable; } 00088 void setData(const char* data) { Request.setBody(data); } 00089 const CzString& getData() const { return Request.getBody(); } 00090 protected: 00091 CzHttpRequest Request; 00092 void ProcessEventActions(unsigned int event_name); 00093 00094 00095 public: 00096 CzRemoteReq() : IzXomlResource(), EventsManager(NULL), Variable(NULL) 00097 { 00098 setClassType("remotereq"); 00099 EventsManager = new CzEventManager(); 00100 } 00101 virtual ~CzRemoteReq(); 00102 00103 virtual bool setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta); 00104 bool setProperty(const char* property_name, const CzString& data, bool delta); 00105 virtual bool setProperty(unsigned int property_name, const CzString& data, bool delta); 00106 bool getProperty(const char* property_name, CzXomlProperty& prop); 00107 virtual bool getProperty(unsigned int property_name, CzXomlProperty& prop); 00108 00109 // Implementation of IzXomlClass interface 00110 int LoadFromXoml(IzXomlResource* parebt, bool load_children, CzXmlNode* node); 00111 00112 void MakeRequest(); 00113 void DataReceived(); 00114 00115 // Internal (used by XOML system to setup and cleanup the XOML class properties system 00116 protected: 00117 static CzXomlClassDef* RemoteRequestClassDef; // XOML class definition 00118 public: 00119 static void InitClass(); 00120 static void ReleaseClass(); 00121 static bool _setName(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00122 static CzXomlProperty _getName(IzXomlResource* target); 00123 static bool _setTag(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00124 static bool _setURL(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00125 static CzXomlProperty _getURL(IzXomlResource* target); 00126 static bool _setData(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00127 static CzXomlProperty _getData(IzXomlResource* target); 00128 static bool _setOnResponse(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00129 static bool _setOnError(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00130 static bool _setPost(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00131 static CzXomlProperty _getPost(IzXomlResource* target); 00132 static bool _setVariable(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00133 static CzXomlProperty _getVariable(IzXomlResource* target); 00134 }; 00135 00136 /** 00137 @class CzRemoteReqCreator 00138 00139 @brief CzRemoteReqCreator - Creates an instance of a RemoteReq. 00140 00141 */ 00142 00143 class CzRemoteReqCreator : public IzXomlClassCreator 00144 { 00145 public: 00146 CzRemoteReqCreator() 00147 { 00148 setClassName("remotereq"); 00149 } 00150 IzXomlResource* CreateInstance(IzXomlResource* parent) { return new CzRemoteReq(); } 00151 }; 00152 00153 /// @} 00154 00155 00156 #endif // _CZ_REMOTEREQ_H_