summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/utils.h
diff options
context:
space:
mode:
authorFishbone <fishbone@miranda-ng.org>2013-06-02 16:19:21 +0000
committerFishbone <fishbone@miranda-ng.org>2013-06-02 16:19:21 +0000
commitab7e0b08fa8c31cf1d468ab4b3c660e2b1836811 (patch)
tree52977603ea0f431adff16573d3d5b46a95843c7f /protocols/WhatsApp/src/utils.h
parent8320783f99419db1e40346fdb292c19ee008948b (diff)
Added WhatsApp-protocol
git-svn-id: http://svn.miranda-ng.org/main/trunk@4861 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/utils.h')
-rw-r--r--protocols/WhatsApp/src/utils.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/protocols/WhatsApp/src/utils.h b/protocols/WhatsApp/src/utils.h
new file mode 100644
index 0000000000..e6686d1764
--- /dev/null
+++ b/protocols/WhatsApp/src/utils.h
@@ -0,0 +1,111 @@
+#if !defined(WHATS_NG_UTILS_H)
+#define WHATS_NG_UTILS_H
+
+#include "WhatsAPI++/IMutex.h"
+
+template<typename T>
+void CreateProtoService(const char *module,const char *service,
+ int (__cdecl T::*serviceProc)(WPARAM,LPARAM),T *self)
+{
+ char temp[MAX_PATH*2];
+
+ mir_snprintf(temp,sizeof(temp),"%s%s",module,service);
+ CreateServiceFunctionObj(temp,( MIRANDASERVICEOBJ )*(void**)&serviceProc, self );
+}
+
+template<typename T>
+void HookProtoEvent(const char* evt, int (__cdecl T::*eventProc)(WPARAM,LPARAM), T *self)
+{
+ ::HookEventObj(evt,(MIRANDAHOOKOBJ)*(void**)&eventProc,self);
+}
+
+template<typename T>
+HANDLE ForkThreadEx(void (__cdecl T::*thread)(void*),T *self,void *data = 0)
+{
+ return reinterpret_cast<HANDLE>( mir_forkthreadowner(
+ (pThreadFuncOwner)*(void**)&thread,self,data,0));
+}
+
+template<typename T>
+void ForkThread(void (__cdecl T::*thread)(void*),T *self,void *data = 0)
+{
+ CloseHandle(ForkThreadEx(thread,self,data));
+}
+
+class ScopedLock
+{
+public:
+ ScopedLock(HANDLE h, int t = INFINITE) : handle_(h), timeout_(t)
+ {
+ WaitForSingleObject(handle_,timeout_);
+ }
+ ~ScopedLock()
+ {
+ if(handle_)
+ ReleaseMutex(handle_);
+ }
+ void Unlock()
+ {
+ ReleaseMutex(handle_);
+ handle_ = 0;
+ }
+private:
+ HANDLE handle_;
+ int timeout_;
+};
+
+class Mutex : public IMutex
+{
+private:
+ HANDLE handle;
+public:
+ Mutex() : handle(NULL) {}
+
+ virtual ~Mutex()
+ {
+ if (this->handle != NULL)
+ {
+ ReleaseMutex(this->handle);
+ }
+ }
+
+ virtual void lock()
+ {
+ if (this->handle == NULL)
+ {
+ this->handle = CreateMutex(NULL, FALSE, NULL);
+ }
+ }
+
+ virtual void unlock()
+ {
+ ReleaseMutex(this->handle);
+ this->handle = NULL;
+ }
+};
+
+
+std::string getLastErrorMsg();
+
+void UnixTimeToFileTime(time_t t, LPFILETIME pft);
+
+namespace utils
+{
+ namespace debug
+ {
+ int log(std::string file_name, std::string text);
+ };
+
+ namespace conversion
+ {
+ DWORD to_timestamp( std::string data );
+ };
+
+ namespace text
+ {
+ std::string source_get_value(std::string* data, unsigned int argument_count, ...);
+ };
+};
+
+
+#endif \ No newline at end of file