nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NODENETPROTOCOL_H 00024 #define NODENETPROTOCOL_H 00025 00026 #include "NodeItem.h" 00027 #include "NuxCore/TinyXML/tinyxml.h" 00028 00029 //#pragma pack(1) 00030 // 00031 //enum TypeHeader 00032 //{ 00033 // TRANSFER_ACK, 00034 // BYTE_HEADER, 00035 // INT_HEADER, 00036 // STRING_HEADER, 00037 //}; 00038 // 00039 //struct NUX_HEADER_PACKET 00040 //{ 00041 // NSockAddrIn address; 00042 // unsigned long Code; // => 4 bytes (the header type or protocol) 00043 // unsigned long Type; // => 4 bytes (the service requested/packet type) 00044 // unsigned long Handle; // => 4 bytes (the client/connection handle) 00045 // unsigned long Len; // => 4 bytes (the data len) 00046 //}; 00047 // 00048 // 00049 //struct NUX_DATA_PACKET 00050 //{ 00051 // //NSockAddrIn address; 00052 // BYTE data[1024]; 00053 //}; 00054 // 00055 //struct NUX_DATA_HEADER 00056 //{ 00057 // BYTE data0[1024]; 00058 // BYTE data1[1024]; 00059 //}; 00060 // 00061 //#pragma pack() 00062 00063 #define NODE_XML_NET_PROTOCOL 1 00064 00065 namespace nux 00066 { 00067 00068 enum NodeParameterType 00069 { 00070 NODE_TYPE_UNDEFINED = 1, 00071 NODE_TYPE_FOLDER, 00072 NODE_TYPE_BOOL, 00073 NODE_TYPE_CHECKBOX, 00074 NODE_TYPE_SPINBOX, 00075 NODE_TYPE_DOUBLESPINBOX, 00076 NODE_TYPE_COMBOSIMPLE, 00077 NODE_TYPE_COMBOCOMPLEX, 00078 NODE_TYPE_VECTOR3, 00079 NODE_TYPE_VECTOR4, 00080 NODE_TYPE_RGB, 00081 NODE_TYPE_RGBA, 00082 NODE_TYPE_STATICTEXT, 00083 NODE_TYPE_SPLINE, 00084 NODE_TYPE_EDITTEXT, 00085 NODE_TYPE_RANGE, 00086 NODE_TYPE_RANGEINTEGER, 00087 NODE_TYPE_INTVALUATOR, 00088 NODE_TYPE_DOUBLEVALUATOR, 00089 NODE_TYPE_VECTORVALUATOR, 00090 NODE_TYPE_COLORPREVIEW, 00091 NODE_TYPE_MATRIX4PREVIEW, 00092 NODE_TYPE_MATRIX3PREVIEW, 00093 00094 NODE_TYPE_FORCE_DWORD = 0x7fffffff, 00095 }; 00096 00097 #if NODE_XML_NET_PROTOCOL 00098 bool QueryNodeXMLIntAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, int *Value, int searchid); 00099 bool QueryNodeXMLDoubleAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, double *Value, int searchid); 00100 bool QueryNodeXMLAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, std::string &Value, int searchid); 00101 bool QueryNodeXMLAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, std::string &Value, int searchid); 00102 bool QueryNodeXMLStringAttribute (const TiXmlElement *elementxml, const TCHAR *attribute, tstring &Value, int searchid); 00103 #endif 00104 00105 class NodeNetCom: public NodeItem 00106 { 00107 NUX_DECLARE_OBJECT_TYPE (NodeNetCom, NodeItem); 00108 public: 00110 NodeNetCom *FindNodeID (int id); 00112 NodeNetCom *FindChildNodeID (int id); 00113 00114 #if NODE_XML_NET_PROTOCOL 00115 virtual TiXmlElement *ToXML() const; 00116 virtual bool FromXML (const TiXmlElement *elementxml); 00118 virtual bool CreateFromXML (const TiXmlElement *elementxml); 00119 00121 // automatically take care of parsing in and out their own children. For instance, Vector3PropertyItem. 00122 virtual bool SkipChild() const 00123 { 00124 return false; 00125 } 00126 00127 // virtual bool QueryNodeXMLIntAttribute(const TiXmlElement* elementxml, const char* attribute, int* Value, int id); 00128 // virtual bool QueryNodeXMLDoubleAttribute(const TiXmlElement* elementxml, const char* attribute, double* Value, int id); 00129 // virtual bool QueryNodeXMLAttribute(const TiXmlElement* elementxml, const char* attribute, std::string& Value, int id); 00130 protected: 00131 void SetNodeXMLAttributes (TiXmlElement *elementxml) const; 00132 void GetNodeXMLAttributes (const TiXmlElement *elementxml); 00133 00134 #endif 00135 00136 public: 00137 void DeleteChildren(); 00138 00139 const TCHAR *GetName() const 00140 { 00141 return m_Name.GetTCharPtr(); 00142 } 00143 void SetName (const TCHAR *str) 00144 { 00145 m_Name = str; 00146 } 00147 00148 protected: 00149 NodeNetCom (const TCHAR *Name, NodeParameterType type = NODE_TYPE_UNDEFINED); 00150 virtual ~NodeNetCom() {}; 00151 00152 void SetParameterType (NodeParameterType t) 00153 { 00154 m_Type = t; 00155 } 00156 NodeParameterType GetParameterType() const 00157 { 00158 return m_Type; 00159 } 00160 int GetID() const 00161 { 00162 return m_ID; 00163 } 00164 void SetID (int id) 00165 { 00166 m_ID = id; 00167 } 00168 void SetEnable (bool b) 00169 { 00170 m_Enable = b ? 1 : 0; 00171 } 00172 int IsEnable() const 00173 { 00174 return m_Enable; 00175 } 00176 void SetVisible (bool b) 00177 { 00178 m_Visible = b ? 1 : 0; 00179 } 00180 int IsVisible() const 00181 { 00182 return m_Visible; 00183 } 00184 private: 00185 00186 static int m_IDGenerator; 00187 NString m_Name; 00188 NodeParameterType m_Type; 00189 int m_Enable; // true is client can change the value. 00190 int m_Visible; // true, if visible to the client. 00191 int m_ID; // ID for network communications 00192 00193 friend class ParameterManagerImpl; 00194 }; 00195 00196 00197 } 00198 00199 #endif // NODENETPROTOCOL_H 00200