summaryrefslogtreecommitdiff
path: root/plugins/MirFox/src/MirFoxCommons
diff options
context:
space:
mode:
authorSzymon Tokarz <wsx22@o2.pl>2016-05-31 21:41:30 +0000
committerSzymon Tokarz <wsx22@o2.pl>2016-05-31 21:41:30 +0000
commit9ba730bc48e44630b418f4214aee57c7b7c987bd (patch)
treecc9a0341bcc2ab947b9047890bf0e1b88ad38737 /plugins/MirFox/src/MirFoxCommons
parente2a1d9a9b2cf04583a3e97a9a2305256357cc443 (diff)
[MirFox]
Immediately refresh data in Firefox menu when Miranda contact or account is added, renamed, deleted, enabled or disabled, hide or unhide. Add "Add acount to contact name" option. git-svn-id: http://svn.miranda-ng.org/main/trunk@16892 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirFox/src/MirFoxCommons')
-rw-r--r--plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.cpp124
-rw-r--r--plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.h10
2 files changed, 133 insertions, 1 deletions
diff --git a/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.cpp b/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.cpp
index 7f30a49f4c..18fafa241e 100644
--- a/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.cpp
+++ b/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.cpp
@@ -64,7 +64,7 @@ const boost::interprocess::offset_t SMUCONST_MSM_RECORDS_OFFSET = SMUCONST_M
const boost::interprocess::offset_t SMUCONST_MSM_RECORD_TYPE_RECOFFSET = 0;
const std::size_t SMUCONST_MSM_RECORD_TYPE_SIZE = sizeof(char); //1B
- // [O]Option, [T]Translation, [A]Account, [G]Group, [C]Contact
+ // [O]Option, [T]Translation, [A]Account, [G]Group, [C]Contact, [D]Deleted item
const boost::interprocess::offset_t SMUCONST_MSM_RECORD_HANDLE_RECOFFSET = SMUCONST_MSM_RECORD_TYPE_RECOFFSET + SMUCONST_MSM_RECORD_TYPE_SIZE;
const std::size_t SMUCONST_MSM_RECORD_HANDLE_SIZE = sizeof(uint64_t); //8B
// {AGC} miranda HANDLE to account/group/contact - HANDLE 32/64b, {O} option id, {T} translation id
@@ -189,6 +189,128 @@ SharedMemoryUtils::addContactToSM(uint64_t mirandaContactHandle, uint64_t mirand
}
+
+
+void
+SharedMemoryUtils::refreshMsm_Add(char type, uint64_t mirandaId, std::wstring& displayName)
+{
+ logger->log_p(L"SharedMemoryUtils.refreshMsm_Add type=[%c], mirandaId=[%I64u]", type, mirandaId);
+
+ if (type == 'A'){
+ addAccountToSM(mirandaId, displayName);
+ } else if (type == 'C'){
+ addContactToSM(mirandaId, (uint64_t)NULL, (uint64_t)1, displayName);
+ }
+
+ return;
+}
+
+void
+SharedMemoryUtils::refreshMsm_Edit(char type, uint64_t mirandaId, std::wstring& displayName)
+{
+ logger->log_p(L"SharedMemoryUtils.refreshMsm_Edit type=[%c], mirandaId=[%I64u]", type, mirandaId);
+
+ boost::ptr_list<boost::interprocess::windows_shared_memory>::iterator msmListIter;
+ for (msmListIter = msmList.begin(); msmListIter != msmList.end(); msmListIter++){
+
+ for (int recordNo = 0; recordNo < SMUCONST_MSM_RECORDS_COUNT; recordNo++ ){
+
+ boost::interprocess::mapped_region region1(
+ *msmListIter,
+ boost::interprocess::read_only,
+ SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_TYPE_RECOFFSET,
+ SMUCONST_MSM_RECORD_TYPE_SIZE
+ );
+ char* recordTypePtr = static_cast<char*>(region1.get_address());
+
+ if (*recordTypePtr == type){
+
+ boost::interprocess::mapped_region region2(
+ *msmListIter,
+ boost::interprocess::read_only,
+ SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_HANDLE_RECOFFSET,
+ SMUCONST_MSM_RECORD_HANDLE_SIZE
+ );
+ uint64_t* agcHandlePtr = static_cast<uint64_t*>(region2.get_address());
+
+ if (*agcHandlePtr == mirandaId){
+
+ boost::interprocess::mapped_region region3(
+ *msmListIter,
+ boost::interprocess::read_write,
+ SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_DNAME_RECOFFSET,
+ SMUCONST_MSM_RECORD_DNAME_SIZE
+ );
+ wchar_t* recordValuePtr = static_cast<wchar_t*>(region3.get_address());
+ wcsncpy_s(recordValuePtr, SMUCONST_MSM_RECORD_DNAME_SIZEC, displayName.c_str(), _TRUNCATE);
+
+ logger->log(L"SharedMemoryUtils::refreshMsm_Edit record found and edited");
+
+ // unique record found and edited
+ return;
+ }
+
+ }
+
+ }
+
+ }
+
+ return;
+}
+
+
+
+void
+SharedMemoryUtils::refreshMsm_Delete(char type, uint64_t mirandaId)
+{
+ logger->log_p(L"SharedMemoryUtils.refreshMsm_Delete type=[%c], mirandaId=[%I64u]", type, mirandaId);
+
+ boost::ptr_list<boost::interprocess::windows_shared_memory>::iterator msmListIter;
+ for (msmListIter = msmList.begin(); msmListIter != msmList.end(); msmListIter++){
+
+ for (int recordNo = 0; recordNo < SMUCONST_MSM_RECORDS_COUNT; recordNo++ ){
+
+ boost::interprocess::mapped_region region1(
+ *msmListIter,
+ boost::interprocess::read_write,
+ SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_TYPE_RECOFFSET,
+ SMUCONST_MSM_RECORD_TYPE_SIZE
+ );
+ char* recordTypePtr = static_cast<char*>(region1.get_address());
+
+ if (*recordTypePtr == type){
+
+ boost::interprocess::mapped_region region2(
+ *msmListIter,
+ boost::interprocess::read_only,
+ SMUCONST_MSM_HEADER_SIZE + (recordNo * SMUCONST_MSM_RECORD_SIZE) + SMUCONST_MSM_RECORD_HANDLE_RECOFFSET,
+ SMUCONST_MSM_RECORD_HANDLE_SIZE
+ );
+ uint64_t* agcHandlePtr = static_cast<uint64_t*>(region2.get_address());
+
+ if (*agcHandlePtr == mirandaId){
+
+ *recordTypePtr = 'D'; //[D] deleted - will not be read by other sm clients (even older)
+
+ logger->log(L"SharedMemoryUtils::refreshMsm_Delete record found and deleted");
+
+ // unique record found and edited
+ return;
+ }
+
+ }
+
+ }
+
+ }
+
+ return;
+}
+
+
+
+
int
SharedMemoryUtils::commitSM()
{
diff --git a/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.h b/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.h
index 8ccc1494cf..8bed5e1624 100644
--- a/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.h
+++ b/plugins/MirFox/src/MirFoxCommons/MirFoxCommons_sharedMemory.h
@@ -93,6 +93,16 @@ public:
//call after openOrCreateSM and after creating sm thread
int commitSM();
+
+ // new functions to support refresh data in SM (compatible with v.4 SM version)
+ // add record in working Miranda shared memory
+ void refreshMsm_Add(char type, uint64_t mirandaId, std::wstring& displayName);
+ // edit record in working Miranda shared memory
+ void refreshMsm_Edit(char type, uint64_t mirandaId, std::wstring& displayName);
+ // remove record in working Miranda shared memory
+ void refreshMsm_Delete(char type, uint64_t mirandaId);
+
+
//delete returned sm object after use
boost::interprocess::windows_shared_memory* getSmById(const char* smName, std::size_t smSize);