RakNetCSharpExtends.i 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. //--------------------------------Extends-----------------------------------
  2. //This file extends classes with new C++ code, note that not all things are possible because
  3. //while typically it acts like the code is inserted into the class, it isn't really
  4. //The extends are generated in the wrapper
  5. //An example of a problem is accessing private variables and functions.
  6. //Also instead of just calling the function in the class you use a pointer called self that is a pointer to the object
  7. %extend RakNet::BitStream
  8. {
  9. inline const char * CSharpStringReader(const char * inString)
  10. {
  11. self->Read((char *)inString);
  12. return inString;
  13. }
  14. inline bool CSharpByteReader(unsigned char* inOutByteArray,unsigned int numberOfBytes)
  15. {
  16. return self->Read((char *)inOutByteArray,numberOfBytes);
  17. }
  18. inline char * CSharpStringReaderCompressedDelta(char * inString)
  19. {
  20. self->ReadCompressedDelta(inString);
  21. return inString;
  22. }
  23. inline char * CSharpStringReaderDelta( char * inString)
  24. {
  25. self->ReadDelta(inString);
  26. return inString;
  27. }
  28. inline char * CSharpStringReaderCompressed(char * inString)
  29. {
  30. self->ReadCompressed(inString);
  31. return inString;
  32. }
  33. void Write( unsigned char* inputByteArray, const unsigned int numberOfBytes )
  34. {
  35. self->Write((const char*)inputByteArray,numberOfBytes);
  36. }
  37. BitSize_t CSharpCopyDataHelper(unsigned char* inOutByteArray)
  38. {
  39. BitSize_t returnVal;
  40. returnVal=self->GetNumberOfBitsAllocated();
  41. memcpy(inOutByteArray, self->GetData(), sizeof(unsigned char) * (size_t) ( BITS_TO_BYTES( returnVal ) ) );
  42. return returnVal;
  43. }
  44. inline char * CSharpPrintBitsHelper(char * inString)
  45. {
  46. self->PrintBits(inString);
  47. return inString;
  48. }
  49. inline char * CSharpPrintHexHelper(char * inString)
  50. {
  51. self->PrintHex(inString);
  52. return inString;
  53. }
  54. void Serialize(bool writeToBitstream, unsigned char* inputByteArray, const unsigned int numberOfBytes )
  55. {
  56. self->Serialize(writeToBitstream,(char*)inputByteArray,numberOfBytes);
  57. }
  58. bool ReadAlignedBytesSafe(unsigned char *inOutByteArray, int inputLength, const int maxBytesToRead )
  59. {
  60. return self->ReadAlignedBytesSafe( (char *)inOutByteArray,inputLength, maxBytesToRead );
  61. }
  62. bool ReadAlignedBytesSafe(unsigned char *inOutByteArray, unsigned int inputLength, const unsigned int maxBytesToRead )
  63. {
  64. return self->ReadAlignedBytesSafe((char *)inOutByteArray,inputLength, maxBytesToRead );
  65. }
  66. void WriteAlignedVar8(unsigned char *inByteArray)
  67. {
  68. self->WriteAlignedVar8((const char *)inByteArray);
  69. }
  70. bool ReadAlignedVar8(unsigned char *inOutByteArray)
  71. {
  72. return self->ReadAlignedVar8((char *)inOutByteArray);
  73. }
  74. void WriteAlignedVar16(unsigned char *inByteArray)
  75. {
  76. self->WriteAlignedVar16((const char *)inByteArray);
  77. }
  78. bool ReadAlignedVar16(unsigned char *inOutByteArray)
  79. {
  80. return self->ReadAlignedVar16((char *)inOutByteArray);
  81. }
  82. void WriteAlignedVar32(unsigned char *inByteArray)
  83. {
  84. self->WriteAlignedVar32((const char *)inByteArray);
  85. }
  86. bool ReadAlignedVar32(unsigned char *inOutByteArray)
  87. {
  88. return self->ReadAlignedVar32((char *)inOutByteArray);
  89. }
  90. void WriteAlignedBytesSafe( unsigned char *inByteArray, const unsigned int inputLength, const unsigned int maxBytesToWrite )
  91. {
  92. self->WriteAlignedBytesSafe((const char *)inByteArray, inputLength, maxBytesToWrite );
  93. }
  94. }
  95. %define RAKPEERANDINTERFACEEXTEND()
  96. {
  97. uint32_t Send( unsigned char *inByteArray, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast )
  98. {
  99. return self->Send((const char*)inByteArray,length,priority,reliability,orderingChannel,systemIdentifier,broadcast);
  100. }
  101. void SendLoopback( unsigned char *inByteArray, const int length )
  102. {
  103. self->SendLoopback( (const char *)inByteArray, length );
  104. }
  105. void SetOfflinePingResponse( unsigned char *inByteArray, const unsigned int length )
  106. {
  107. self->SetOfflinePingResponse((const char *) inByteArray,length);
  108. }
  109. bool AdvertiseSystem( const char *host, unsigned short remotePort, unsigned char *inByteArray, int dataLength, unsigned connectionSocketIndex=0 )
  110. {
  111. return self->AdvertiseSystem(host,remotePort,(const char *) inByteArray,dataLength,connectionSocketIndex);
  112. }
  113. const char *CSharpGetIncomingPasswordHelper( const char* passwordData, int *passwordDataLength )
  114. {
  115. self->GetIncomingPassword((char*)passwordData,passwordDataLength);
  116. return passwordData;
  117. }
  118. void SetIncomingPassword( unsigned char* passwordDataByteArray, int passwordDataLength )
  119. {
  120. self->SetIncomingPassword((char*)passwordDataByteArray,passwordDataLength);
  121. }
  122. void GetIncomingPassword( unsigned char* passwordDataByteArray, int *passwordDataLength )
  123. {
  124. self->GetIncomingPassword((char*)passwordDataByteArray,passwordDataLength);
  125. }
  126. void CSharpGetOfflinePingResponseHelper( unsigned char *inOutByteArray, unsigned int *outLength )
  127. {
  128. char * tmp=(char *)inOutByteArray;
  129. self->GetOfflinePingResponse(&tmp,outLength);
  130. memcpy(inOutByteArray,tmp,(size_t)*outLength);
  131. }
  132. bool GetConnectionList( DataStructures::List <SystemAddress> * remoteSystems, unsigned short *numberOfSystems ) const
  133. {
  134. SystemAddress inSys[256];
  135. bool returnVal = self->GetConnectionList(inSys,numberOfSystems);
  136. if(remoteSystems!=NULL)
  137. {
  138. for (int i=0;i<*numberOfSystems;i++)
  139. {
  140. remoteSystems->Insert(inSys[i],__FILE__,__LINE__);
  141. }
  142. }
  143. return returnVal;
  144. }
  145. }
  146. %enddef
  147. %extend RakNet::RakPeerInterface
  148. RAKPEERANDINTERFACEEXTEND()
  149. %extend RakNet::RakPeer
  150. RAKPEERANDINTERFACEEXTEND()
  151. %extend RakNet::RakString
  152. {
  153. void AppendBytes(unsigned char *inByteArray, unsigned int count)
  154. {
  155. self->AppendBytes((const char *)inByteArray,count);
  156. }
  157. }
  158. //Removed from interface, commented rather than removed in case needed later
  159. /*
  160. %extend RakNet::PluginInterface2
  161. {
  162. void OnDirectSocketReceive(unsigned char *inByteArray, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
  163. {
  164. self->OnDirectSocketReceive((const char *)inByteArray, bitsUsed, remoteSystemAddress);
  165. }
  166. void OnDirectSocketSend(unsigned char *inByteArray, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
  167. {
  168. self->OnDirectSocketSend((const char *)inByteArray, bitsUsed, remoteSystemAddress);
  169. }
  170. void OnPushBackPacket(unsigned char *inByteArray, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
  171. {
  172. self->OnPushBackPacket((const char *)inByteArray, bitsUsed, remoteSystemAddress);
  173. }
  174. }*/
  175. %define STRUCT_UNSIGNED_CHAR_ARRAY_EXTEND(IN_FUNCTION_NAME,IN_DATA_NAME,LENGTH_MEMBER_VAR)
  176. void IN_FUNCTION_NAME (unsigned char * inByteArray,int numBytes)
  177. {
  178. if (self->IN_DATA_NAME!=NULL)
  179. {
  180. rakFree_Ex(self->IN_DATA_NAME, __FILE__, __LINE__);
  181. }
  182. //create new with size
  183. self->IN_DATA_NAME=(unsigned char*) rakMalloc_Ex(numBytes, __FILE__, __LINE__);
  184. //copy
  185. memcpy( self->IN_DATA_NAME,inByteArray, numBytes );
  186. self->LENGTH_MEMBER_VAR=numBytes;
  187. }
  188. %enddef
  189. %extend RakNet::Packet
  190. {
  191. Packet()
  192. {
  193. Packet * newPacket = new Packet();
  194. newPacket->data=NULL;
  195. return newPacket;
  196. }
  197. STRUCT_CUSTOM_UNSIGNED_CHAR_ARRAY_TYPEMAP(dataIsCached,dataCache,unsigned char * data,SetPacketData,Packet_data_get,Packet,length)
  198. STRUCT_UNSIGNED_CHAR_ARRAY_EXTEND(SetPacketData,data,length)
  199. }
  200. //Removed from interface, commented rather than removed in case needed later
  201. /*
  202. %extend InternalPacket
  203. {
  204. STRUCT_CUSTOM_UNSIGNED_CHAR_ARRAY_TYPEMAP(dataIsCached,dataCache,unsigned char * data,SetInternalPacketData,InternalPacket_data_get,InternalPacket,dataBitLength/8)
  205. STRUCT_UNSIGNED_CHAR_ARRAY_EXTEND(SetInternalPacketData,data)
  206. }*/
  207. %define STRUCT_UNSIGNED_INT_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(IN_FUNCTION_NAME,IN_DATA_NAME)
  208. void IN_FUNCTION_NAME (unsigned int * inUnsignedIntArray,int numInts)
  209. {
  210. for (int i=0;i<numInts;i++)
  211. {
  212. if (i>=NUMBER_OF_PRIORITIES)
  213. {break;}
  214. self->IN_DATA_NAME[i]=inUnsignedIntArray[i];
  215. }
  216. }
  217. %enddef
  218. %define STRUCT_UNSIGNED_INT64_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(IN_FUNCTION_NAME,IN_DATA_NAME)
  219. void IN_FUNCTION_NAME (unsigned long long int * inUint64Array,int numUint64)
  220. {
  221. for (int i=0;i<numUint64;i++)
  222. {
  223. if (i>=RNS_PER_SECOND_METRICS_COUNT)
  224. {break;}
  225. self->IN_DATA_NAME[i]=inUint64Array[i];
  226. }
  227. }
  228. %enddef
  229. %define STRUCT_DOUBLE_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(IN_FUNCTION_NAME,IN_DATA_NAME)
  230. void IN_FUNCTION_NAME (double * inDoubleArray,int numDoubles)
  231. {
  232. for (int i=0;i<numDoubles;i++)
  233. {
  234. if (i>=NUMBER_OF_PRIORITIES)
  235. {break;}
  236. self->IN_DATA_NAME[i]=inDoubleArray[i];
  237. }
  238. }
  239. %enddef
  240. %extend RakNet::RakNetStatistics
  241. {
  242. STRUCT_DOUBLE_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(SetBytesInSendBuffer,bytesInSendBuffer);
  243. STRUCT_UNSIGNED_INT_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(SetMessageInSendBuffer,messageInSendBuffer);
  244. STRUCT_UNSIGNED_INT64_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(SetRunningTotal,runningTotal);
  245. STRUCT_UNSIGNED_INT64_ARRAY_EXTEND_SPECIAL_RAKNETSTATISTICS(SetValueOverLastSecond,valueOverLastSecond);
  246. }
  247. %extend FileProgressStruct
  248. {
  249. FileProgressStruct()
  250. {
  251. FileProgressStruct * returnVal= new FileProgressStruct();
  252. returnVal->firstDataChunk=NULL;
  253. returnVal->iriDataChunk=NULL;
  254. return returnVal;
  255. }
  256. void SetFirstDataChunk (unsigned char * inByteArray,int numBytes)
  257. {
  258. if (self->firstDataChunk!=NULL)
  259. {
  260. rakFree_Ex(self->firstDataChunk, __FILE__, __LINE__);
  261. }
  262. //create new with size
  263. self->firstDataChunk=(char*) rakMalloc_Ex(numBytes, __FILE__, __LINE__);
  264. //copy
  265. memcpy( self->firstDataChunk,inByteArray, numBytes );
  266. }
  267. void SetIriDataChunk(unsigned char * inByteArray,int numBytes)
  268. {
  269. if (self->iriDataChunk!=NULL)
  270. {
  271. rakFree_Ex(self->iriDataChunk, __FILE__, __LINE__);
  272. }
  273. //create new with size
  274. self->iriDataChunk=(char*) rakMalloc_Ex(numBytes, __FILE__, __LINE__);
  275. //copy
  276. memcpy( self->iriDataChunk,inByteArray, numBytes );
  277. }
  278. }
  279. %extend OnFileStruct
  280. {
  281. OnFileStruct()
  282. {
  283. OnFileStruct * returnVal= new OnFileStruct();
  284. returnVal->fileData=NULL;
  285. return returnVal;
  286. }
  287. void SetFileData(unsigned char * inByteArray,int numBytes)
  288. {
  289. if(self->fileData!=NULL)
  290. {
  291. rakFree_Ex(self->fileData, __FILE__, __LINE__);
  292. }
  293. //create new with size
  294. self->fileData=(char*) rakMalloc_Ex(numBytes, __FILE__, __LINE__);
  295. //copy
  296. memcpy( self->fileData,inByteArray, numBytes );
  297. }
  298. }
  299. %extend RakNet::IncrementalReadInterface
  300. {
  301. unsigned int GetFilePart( const char *filename, unsigned int startReadBytes, unsigned int numBytesToRead, unsigned char *inOutByteArray, FileListNodeContext context)
  302. {
  303. return self->GetFilePart( filename, startReadBytes, numBytesToRead, (void *)inOutByteArray, context);
  304. }
  305. }
  306. %extend DataStructures::ByteQueue
  307. {
  308. void WriteBytes(unsigned char *inByteArray, unsigned length, const char *file, unsigned int line)
  309. {
  310. self->WriteBytes((const char *)inByteArray, length, file, line);
  311. }
  312. bool ReadBytes(unsigned char *inOutByteArray, unsigned maxLengthToRead, bool peek)
  313. {
  314. return self->ReadBytes((char *)inOutByteArray, maxLengthToRead, peek);
  315. }
  316. unsigned char* PeekContiguousBytesHelper(unsigned int *outLength) const
  317. {
  318. unsigned char* returnVal=(unsigned char* ) self->PeekContiguousBytes(outLength);
  319. return returnVal;
  320. }
  321. }
  322. %extend RakNet::PacketLogger
  323. {
  324. const char * FormatLineHelper(char* into, const char* dir, const char* type, unsigned int packet, unsigned int frame, unsigned char messageIdentifier, const BitSize_t bitLen, unsigned long long time, const SystemAddress& local, const SystemAddress& remote,unsigned int splitPacketId, unsigned int splitPacketIndex, unsigned int splitPacketCount, unsigned int orderingIndex)
  325. {
  326. self->FormatLine(into,dir,type,packet, frame,messageIdentifier, bitLen,time, local, remote,splitPacketId, splitPacketIndex, splitPacketCount, orderingIndex);
  327. return into;
  328. }
  329. const char * FormatLineHelper(char* into, const char* dir, const char* type, unsigned int packet, unsigned int frame, const char* idToPrint, const BitSize_t bitLen, unsigned long long time, const SystemAddress& local, const SystemAddress& remote,unsigned int splitPacketId, unsigned int splitPacketIndex, unsigned int splitPacketCount, unsigned int orderingIndex)
  330. {
  331. self->FormatLine(into,dir,type,packet,frame, idToPrint, bitLen, time, local, remote, splitPacketId, splitPacketIndex, splitPacketCount, orderingIndex);
  332. return into;
  333. }
  334. }
  335. %extend Cell
  336. {
  337. void Set(unsigned char *inByteArray, int inputLength)
  338. {
  339. self->Set((const char *)inByteArray,inputLength);
  340. }
  341. void Get(unsigned char *inOutByteArray, int *outputLength)
  342. {
  343. self->Get((char *)inOutByteArray,outputLength);
  344. }
  345. char *GetHelper(char *output)
  346. {
  347. self->Get(output);
  348. return output;
  349. }
  350. }
  351. %extend Row
  352. {
  353. void UpdateCell(unsigned columnIndex, int byteLength, unsigned char *inByteArray)
  354. {
  355. self->UpdateCell(columnIndex, byteLength, (const char *)inByteArray);
  356. }
  357. }
  358. %define STRUCT_CHAR_TO_BYTE_ARRAY_TYPEMAP_INSIDE_EXTEND(BOOLNAME,CACHENAME,IN_DATA_CHANGE_FUNCTION,IN_DATA_GET_FUNCTION,IN_CLASS,IN_LEN_ATTRIBUTE,IN_DATA_NAME)
  359. %typemap(imtype, out="IntPtr") char * IN_DATA_NAME "IntPtr"
  360. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP(BOOLNAME,CACHENAME,char * IN_DATA_NAME,byte,byte,IN_DATA_CHANGE_FUNCTION,IN_DATA_GET_FUNCTION,IN_CLASS,IN_LEN_ATTRIBUTE)
  361. void IN_DATA_CHANGE_FUNCTION (unsigned char * inByteArray,int numBytes)
  362. {
  363. if (self->IN_DATA_NAME!=NULL)
  364. {
  365. rakFree_Ex(self->IN_DATA_NAME, __FILE__, __LINE__);
  366. }
  367. //create new with size
  368. self->IN_DATA_NAME=(char *) rakMalloc_Ex(numBytes, __FILE__, __LINE__);
  369. //copy
  370. memcpy( self->IN_DATA_NAME,inByteArray, numBytes );
  371. self->IN_LEN_ATTRIBUTE=numBytes;
  372. }
  373. %enddef
  374. %extend RakNet::FileListNode
  375. {
  376. FileListNode()
  377. {
  378. FileListNode *returnVal = new FileListNode();
  379. returnVal->data=NULL;
  380. return returnVal;
  381. }
  382. STRUCT_CHAR_TO_BYTE_ARRAY_TYPEMAP_INSIDE_EXTEND(dataIsCached,dataCache,SetData,FileListNode_data_get,RakNet::FileListNode,dataLengthBytes,data)
  383. }
  384. %extend RakNet::TransportInterface
  385. {
  386. void Send( SystemAddress systemAddress, unsigned char * inByteArray)
  387. {
  388. self->Send( systemAddress, (const char *)inByteArray);
  389. }
  390. }
  391. %extend RakNet::FileList
  392. {
  393. void AddFile(const char *filename, const char *fullPathToFile, unsigned char *inByteArray, const unsigned dataLength, const unsigned fileLength, FileListNodeContext context, bool isAReference=false)
  394. {
  395. self->AddFile(filename,fullPathToFile, (const char *)inByteArray, dataLength, fileLength, context,isAReference);
  396. }
  397. }
  398. %extend RakNet::ConnectionGraph2
  399. {
  400. bool GetConnectionListForRemoteSystemHelper(RakNetGUID remoteSystemGuid, DataStructures::List<SystemAddress> * saOut, DataStructures::List<RakNetGUID> * guidOut, unsigned int *inOutLength)
  401. {
  402. SystemAddress * tempInSystemAddress;
  403. RakNetGUID * tempInRakNetGUID;
  404. tempInSystemAddress = new SystemAddress[*inOutLength];
  405. tempInRakNetGUID = new RakNetGUID[*inOutLength];
  406. bool returnVal = self->GetConnectionListForRemoteSystem(remoteSystemGuid,tempInSystemAddress,tempInRakNetGUID,inOutLength);
  407. for (int i=0;i<*inOutLength;i++)
  408. {
  409. saOut->Insert(tempInSystemAddress[i],__FILE__,__LINE__);
  410. guidOut->Insert(tempInRakNetGUID[i],__FILE__,__LINE__);
  411. }
  412. delete [] tempInSystemAddress;
  413. delete [] tempInRakNetGUID;
  414. return returnVal;
  415. }
  416. void GetParticipantListHelper( DataStructures::List<RakNetGUID> * guidOut)
  417. {
  418. DataStructures::OrderedList<RakNetGUID, RakNetGUID> participantList;
  419. self->GetParticipantList(participantList);
  420. for (unsigned int i=0; i < participantList.Size(); i++)
  421. guidOut->Insert(participantList[i],__FILE__,__LINE__);
  422. }
  423. }
  424. %extend DataStructures::BPlusTree<unsigned, DataStructures::Table::Row*, _TABLE_BPLUS_TREE_ORDER>
  425. {
  426. DataStructures::Table::Row* DeleteHelper(const unsigned key, DataStructures::Table::Row* out,bool &outBool)
  427. {
  428. outBool=self->Delete(key,out);
  429. return out;
  430. }
  431. bool BPlusTree<KeyType, DataType, order>::DeleteHelper(const unsigned key)
  432. {
  433. this->DeleteHelper(key);
  434. }
  435. DataStructures::Table::Row* BPlusTree<KeyType, DataType, order>::GetHelper(const unsigned key, DataStructures::Table::Row* out,bool &outBool) const
  436. {
  437. outBool=self->Get(key,out);
  438. return out;
  439. }
  440. }
  441. #ifdef SWIG_ADDITIONAL_AUTOPATCHER
  442. %extend RakNet::AutopatcherServer
  443. {
  444. void StartThreadsHelper(int numThreads, DataStructures::List<AutopatcherRepositoryInterface *> *sqlConnectionPtrArray)
  445. {
  446. AutopatcherRepositoryInterface ** passedArray=NULL;
  447. if (sqlConnectionPtrArray!=NULL)
  448. {
  449. passedArray=&((*sqlConnectionPtrArray)[0]); /*The memory should be contigous since this is a vector class copy. It was last time I checked the implementation. So this will efficiently pass the array without needing to copy it*/
  450. }
  451. self->StartThreads(numThreads,passedArray);
  452. }
  453. }
  454. %extend RakNet::AutopatcherMySQLRepository
  455. {
  456. /// Calls mysql_real_connect with the implicit mySqlConnection
  457. bool Connect (const char *host,const char *user,const char *passwd,const char *db,unsigned int port,const char *unix_socket,unsigned long clientflag)
  458. {
  459. return self->Connect (host,user,passwd,db,port,unix_socket,clientflag);
  460. }
  461. /// Disconnect from the database
  462. void Disconnect(void)
  463. {
  464. return self->Disconnect();
  465. }
  466. /// Returns if we are connected to the database
  467. bool IsConnected(void) const
  468. {
  469. return self->IsConnected();
  470. }
  471. /// If any of the above functions fail, the error string is stored internally. Call this to get it.
  472. const char *GetLastError(void) const
  473. {
  474. return self->GetLastError();
  475. }
  476. /// Returns the result of SELECT LOCALTIMESTAMP
  477. char *GetLocalTimestamp(void)
  478. {
  479. return self->GetLocalTimestamp();
  480. }
  481. }
  482. %extend MemoryCompressor
  483. {
  484. /// Compress a block of data. Pass true to finish if this is the last block in the series. If you don't know if it's the last block, you can call it again with 0 for inputLength
  485. /// \note Data passed to input isn't necessarily immediately compressed to output. You can force a write by passing true to finish.
  486. /// Multiple calls concatenate the written data.
  487. /// \param[in] input A pointer to a block of data
  488. /// \param[in] inputLength The length of input
  489. /// \param[in] finish Write the last of the data.
  490. bool Compress(unsigned char *inputByteArray, const unsigned inputLength, bool finish)
  491. {
  492. return self->Compress((char *) inputByteArray,inputLength,finish);
  493. }
  494. }
  495. %extend MemoryDecompressor
  496. {
  497. /// Read \a inputLength bytes of compressed data from \a input
  498. /// Writes the decompressed output to GetOutput(). Note that unlike the class MemoryCompressor, output data is updated immediately and not internally buffered
  499. /// \param[in] input A pointer to a block of data
  500. /// \param[in] inputLength The length of input
  501. /// \param[in] ignoreStreamEnd Normally when Compress is called with finish==true stream end markers are placed. These are honored, such that the read will end early if a stream marker is hit. Pass true to ignore this and just output all the data.
  502. bool Decompress(unsigned char *inputByteArray, const unsigned inputLength, bool ignoreStreamEnd)
  503. {
  504. return self->Decompress((char *) inputByteArray,inputLength,ignoreStreamEnd);
  505. }
  506. }
  507. %extend CompressorBase
  508. {
  509. void GetOutputHelper(unsigned char * inOutByteArray)
  510. {
  511. char * returnByteArray;
  512. returnByteArray=self->GetOutput();
  513. memcpy(inOutByteArray, returnByteArray, self->GetTotalOutputSize() );
  514. }
  515. }
  516. #endif
粤ICP备19079148号