summaryrefslogtreecommitdiff
path: root/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h
diff options
context:
space:
mode:
authorSzymon Tokarz <wsx22@o2.pl>2013-05-27 22:29:01 +0000
committerSzymon Tokarz <wsx22@o2.pl>2013-05-27 22:29:01 +0000
commitc628a13d98fde8d2555cc6fa8628e0b575021bd4 (patch)
treef25e89f902c0ac82c8f138badbca7f29d331ba18 /plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h
parent2f2175b11692b8561fd1018161a62685910d08b0 (diff)
MirFox plugin for Miranda NG added
Version 0.5.0.0 Compatible Firefox addon is now available at: https://addons.mozilla.org/pl/firefox/addon/mirfox/versions/0.5.0.0 or http://wsx22.xpdev-hosted.com/ git-svn-id: http://svn.miranda-ng.org/main/trunk@4826 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h')
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h b/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h
new file mode 100644
index 0000000000..513b720ee7
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h
@@ -0,0 +1,87 @@
+#ifndef _WSX22_IPC_MESSAGEQUEUEBYSM
+#define _WSX22_IPC_MESSAGEQUEUEBYSM
+
+
+
+//message queue by shared memory related definitions
+#define MQCONST_MQSM_TEXT_SIZEC 2042 //number of wchar_t chars in message - now used sharedmemory mode
+
+#define MQTHREAD_TICK_TIME 100 // 100ms - check exit every this time
+#define MQTHREAD_FIRSTRUN_TIME 0 // MQTHREAD_FIRSTRUN_TIME * MQTHREAD_TICK_TIME = 0s - time to first run of checking message queue in mq thread (after thread start)
+#define MQTHREAD_NEXTRUN_TIME 1 // MQTHREAD_NEXTRUN_TIME * MQTHREAD_TICK_TIME = 0s - time to next run of checking message queue in mq thread
+
+
+
+#include "MirFoxCommons_logger.h"
+
+
+
+
+
+
+/**
+ * MessageQueue Utils
+ *
+ * based on Boost Shared Memory, beacouse boost message queue doesn't work between 32bit and 64bit processes (at boost 1.46)
+ *
+ * Singleton pattern based on
+ * http://www.codeproject.com/KB/threads/SingletonThreadSafety.aspx
+ */
+class MessageQueueUtils
+{
+
+public:
+
+ //constructor
+ MessageQueueUtils();
+ //destructor
+ ~MessageQueueUtils();
+
+
+
+ std::string getMqName(uint16_t processId);
+
+ //return 0 if success, >0 if error
+ int createMessageQueue(std::string mqName);
+
+ void unloadMessageQueue(uint16_t unloadedMQProcessId);
+
+ //wchar_t*& - pointer by reference
+ bool tryReceiveMessage (char& menuItemType, char& userActionType, char& userButton, uint64_t& targetHandle, wchar_t*& userActionSelection, size_t uasBuffCSize);
+
+ void sendMessage(int clientRecordId, char menuItemType, char userActionType, char userButton, uint64_t targetHandle, std::wstring userActionSelection);
+
+ uint16_t volatile unloadedMQProcessId;
+
+
+ //static method that returns only instance of SharedMemoryUtils
+ static MessageQueueUtils * getInstance()
+ {
+ //initialized always from one thread at a time
+ if (m_pOnlyOneInstance == NULL) {
+ if (m_pOnlyOneInstance == NULL) {
+ m_pOnlyOneInstance = new MessageQueueUtils();
+ }
+ }
+ return m_pOnlyOneInstance;
+ }
+
+
+private:
+
+ boost::interprocess::windows_shared_memory* volatile mqMirSm;
+
+ std::size_t getMqMirSmTotalSize();
+
+ //CRITICAL_SECTION smCs;
+ HANDLE smMutex;
+
+ //holds one and only object of MySingleton
+ static MessageQueueUtils * m_pOnlyOneInstance;
+
+ MFLogger* logger;
+
+};
+
+
+#endif //#ifndef _WSX22_IPC_MESSAGEQUEUEBYSM