diff options
Diffstat (limited to 'plugins/SeenPlugin')
-rw-r--r-- | plugins/SeenPlugin/src/main.cpp | 9 | ||||
-rw-r--r-- | plugins/SeenPlugin/src/seen.h | 15 | ||||
-rw-r--r-- | plugins/SeenPlugin/src/utils.cpp | 132 |
3 files changed, 64 insertions, 92 deletions
diff --git a/plugins/SeenPlugin/src/main.cpp b/plugins/SeenPlugin/src/main.cpp index 650382c8b6..9dd4e7ea1c 100644 --- a/plugins/SeenPlugin/src/main.cpp +++ b/plugins/SeenPlugin/src/main.cpp @@ -47,15 +47,10 @@ DBVTranslation idleTr[TRANSNUMBER]={ };
BOOL includeIdle;
-logthread_info **contactQueue = NULL;
-int contactQueueSize = 0;
+LIST<logthread_info> arContacts(16, LIST<logthread_info>::FTSortFunc(HandleKeySortT));
int MainInit(WPARAM wparam,LPARAM lparam)
{
- contactQueueSize = 16*sizeof(logthread_info *);
- contactQueue = (logthread_info **)malloc(contactQueueSize);
- memset(&contactQueue[0], 0, contactQueueSize);
- contactQueueSize = 16;
includeIdle = (BOOL )db_get_b(NULL,S_MOD,"IdleSupport",1);
HookEvent(ME_OPT_INITIALISE, OptionsInit);
@@ -84,7 +79,6 @@ int MainInit(WPARAM wparam,LPARAM lparam) CallService("DBEditorpp/RegisterSingleModule", (WPARAM)S_MOD, 0);
db_set_s(NULL,"Uninstall",Translate("Last seen"),S_MOD);
-
if ( ServiceExists(MS_TIPPER_ADDTRANSLATION))
for (int i=0; i < TRANSNUMBER; i++)
CallService(MS_TIPPER_ADDTRANSLATION, 0, (LPARAM)&idleTr[i]);
@@ -119,6 +113,7 @@ extern "C" __declspec(dllexport) int Unload(void) if (ehmissed)
UnhookEvent(ehmissed);
+ arContacts.destroy();
CloseHandle(g_hShutdownEvent);
UninitMenuitem();
return 0;
diff --git a/plugins/SeenPlugin/src/seen.h b/plugins/SeenPlugin/src/seen.h index 9c2e1adc55..1a07999868 100644 --- a/plugins/SeenPlugin/src/seen.h +++ b/plugins/SeenPlugin/src/seen.h @@ -109,19 +109,18 @@ int CheckIfOnline(void); void UninitMenuitem();
void ShowHistory(HANDLE hContact, BYTE isAlert);
-typedef struct logthread_info {
- char sProtoName[MAXMODULELABELLENGTH];
- HANDLE hContact;
- WORD courStatus;
- int queueIndex;
-} logthread_info;
+struct logthread_info
+{
+ HANDLE hContact;
+ char sProtoName[MAXMODULELABELLENGTH];
+ WORD currStatus;
+};
extern HINSTANCE hInstance;
-extern logthread_info **contactQueue;
-extern int contactQueueSize;
extern DWORD StatusColors15bits[];
extern BOOL includeIdle;
extern HANDLE ehmissed;
extern HANDLE ehuserinfo, hmenuitem, ehmissed_proto;
extern DWORD dwmirver;
+extern LIST<logthread_info> arContacts;
\ No newline at end of file diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index 8eb1f01f37..e22fff1911 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -512,7 +512,8 @@ void ShowPopup(HANDLE hcontact, const char * lpzProto, int newStatus) PUAddPopUpT(&ppd);
}
-void myPlaySound(HANDLE hcontact, WORD newStatus, WORD oldStatus){
+void myPlaySound(HANDLE hcontact, WORD newStatus, WORD oldStatus)
+{
if (CallService(MS_IGNORE_ISIGNORED,(WPARAM)hcontact,IGNOREEVENT_USERONLINE)) return;
//oldStatus and hcontact are not used yet
char * soundname=0;
@@ -523,45 +524,17 @@ void myPlaySound(HANDLE hcontact, WORD newStatus, WORD oldStatus){ if (soundname!=0) SkinPlaySound(soundname);
}
-//will give hContact position or zero
-int isContactQueueActive(HANDLE hContact){
- int i = 0;
- if (!hContact) {
-// MessageBox(0,"Is myself in the queue: never","LastSeen-Mod",0);
- return 0;
- }
- for (i=1;i<contactQueueSize;i++) {
- if (contactQueue[i])
- if (contactQueue[i]->hContact==hContact) return i;
- }
- return 0;
-}
-
//will add hContact to queue and will return position;
-int addContactToQueue(HANDLE hContact){
+static logthread_info* addContactToQueue(HANDLE hContact)
+{
int i = 0;
- if (!hContact) {
-// MessageBox(0,"Adding myself to queue","LastSeen-Mod",0);
- return 0;
- }
- for (i=1;i<contactQueueSize;i++) {
- if (!contactQueue[i]) {
- contactQueue[i] = (logthread_info *)malloc(sizeof(logthread_info));
- contactQueue[i]->queueIndex = i;
- contactQueue[i]->hContact = hContact;
- return i;
- }
- }
- //no free space. Create some
- //MessageBox(0,"Creating more space","LastSeen-Mod",0);
- contactQueue = (logthread_info **)realloc(contactQueue,(contactQueueSize+16)*sizeof(logthread_info *));
- memset(&contactQueue[contactQueueSize],0, 16*sizeof(logthread_info *));
- i = contactQueueSize;
- contactQueue[i] = (logthread_info *)malloc(sizeof(logthread_info));
- contactQueue[i]->queueIndex = i;
- contactQueue[i]->hContact = hContact;
- contactQueueSize += 16;
- return i;
+ if (!hContact)
+ return NULL;
+
+ logthread_info *p = (logthread_info*)mir_calloc(sizeof(logthread_info));
+ p->hContact = hContact;
+ arContacts.insert(p);
+ return p;
}
static void waitThread(void *param)
@@ -569,36 +542,41 @@ static void waitThread(void *param) logthread_info* infoParam = (logthread_info*)param;
WORD prevStatus = db_get_w(infoParam->hContact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE);
- Sleep(1500); // I hope in 1.5 second all the needed info will be set
- if (includeIdle)
- if (db_get_dw(infoParam->hContact,infoParam->sProtoName,"IdleTS",0))
- infoParam->courStatus &=0x7FFF;
-
- if (infoParam->courStatus != prevStatus){
- db_set_w(infoParam->hContact,S_MOD,"OldStatus",(WORD)(prevStatus|0x8000));
+
+ // I hope in 1.5 second all the needed info will be set
+ if ( WaitForSingleObject(g_hShutdownEvent, 1500) == WAIT_TIMEOUT) {
if (includeIdle)
- db_set_b(infoParam->hContact,S_MOD,"OldIdle",(BYTE)((prevStatus&0x8000)==0));
+ if (db_get_dw(infoParam->hContact,infoParam->sProtoName,"IdleTS",0))
+ infoParam->currStatus &=0x7FFF;
+
+ if (infoParam->currStatus != prevStatus){
+ db_set_w(infoParam->hContact,S_MOD,"OldStatus",(WORD)(prevStatus|0x8000));
+ if (includeIdle)
+ db_set_b(infoParam->hContact,S_MOD,"OldIdle",(BYTE)((prevStatus&0x8000)==0));
- db_set_w(infoParam->hContact,S_MOD,"StatusTriger",infoParam->courStatus);
+ db_set_w(infoParam->hContact,S_MOD,"StatusTriger",infoParam->currStatus);
+ }
}
- contactQueue[infoParam->queueIndex] = 0;
- free(infoParam);
+ arContacts.remove(infoParam);
+ mir_free(infoParam);
}
int UpdateValues(WPARAM wparam,LPARAM lparam)
{
// to make this code faster
if (!wparam) return 0;
+
+ HANDLE hContact = (HANDLE)wparam;
DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING *)lparam;
//if (CallService(MS_IGNORE_ISIGNORED,(WPARAM)hContact,IGNOREEVENT_USERONLINE)) return 0;
BOOL isIdleEvent = includeIdle?(strcmp(cws->szSetting,"IdleTS")==0):0;
if (strcmp(cws->szSetting,"Status") && strcmp(cws->szSetting,"StatusTriger") && (isIdleEvent==0)) return 0;
if (!strcmp(cws->szModule,S_MOD)) {
//here we will come when Settings/SeenModule/StatusTriger is changed
- WORD prevStatus=db_get_w((HANDLE)wparam, S_MOD, "OldStatus", ID_STATUS_OFFLINE);
+ WORD prevStatus=db_get_w(hContact, S_MOD, "OldStatus", ID_STATUS_OFFLINE);
if (includeIdle){
- if ( db_get_b((HANDLE)wparam, S_MOD, "OldIdle", 0)) prevStatus &= 0x7FFF;
+ if ( db_get_b(hContact, S_MOD, "OldIdle", 0)) prevStatus &= 0x7FFF;
else prevStatus |= 0x8000;
}
if ((cws->value.wVal|0x8000)<=ID_STATUS_OFFLINE)
@@ -607,8 +585,8 @@ int UpdateValues(WPARAM wparam,LPARAM lparam) // avoid repeating the offline status
if ((prevStatus|0x8000)<=ID_STATUS_OFFLINE)
return 0;
- proto = GetContactProto((HANDLE)wparam);
- db_set_b((HANDLE)wparam, S_MOD, "Offline", 1);
+ proto = GetContactProto(hContact);
+ db_set_b(hContact, S_MOD, "Offline", 1);
{
DWORD t;
char *str = (char *)malloc(MAXMODULELABELLENGTH+9);
@@ -616,57 +594,57 @@ int UpdateValues(WPARAM wparam,LPARAM lparam) t = db_get_dw(NULL,S_MOD,str,0);
if (!t) t = time(NULL);
free(str);
- DBWriteTimeTS(t, (HANDLE)wparam);
+ DBWriteTimeTS(t, hContact);
}
if (!db_get_b(NULL,S_MOD,"IgnoreOffline",1))
{
if ( db_get_b(NULL,S_MOD,"FileOutput",0))
- FileWrite((HANDLE)wparam);
+ FileWrite(hContact);
- char *sProto = GetContactProto((HANDLE)wparam);
+ char *sProto = GetContactProto(hContact);
if (CallProtoService(sProto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE) {
- myPlaySound((HANDLE)wparam, ID_STATUS_OFFLINE, prevStatus);
+ myPlaySound(hContact, ID_STATUS_OFFLINE, prevStatus);
if ( db_get_b(NULL, S_MOD, "UsePopups", 0))
- ShowPopup((HANDLE)wparam, sProto, ID_STATUS_OFFLINE);
+ ShowPopup(hContact, sProto, ID_STATUS_OFFLINE);
}
if ( db_get_b(NULL, S_MOD, "KeepHistory", 0))
- HistoryWrite((HANDLE)wparam);
+ HistoryWrite(hContact);
- if ( db_get_b((HANDLE)wparam, S_MOD, "OnlineAlert", 0))
- ShowHistory((HANDLE)wparam, 1);
+ if ( db_get_b(hContact, S_MOD, "OnlineAlert", 0))
+ ShowHistory(hContact, 1);
}
} else {
- if (cws->value.wVal==prevStatus && !db_get_b((HANDLE)wparam, S_MOD, "Offline", 0))
+ if (cws->value.wVal==prevStatus && !db_get_b(hContact, S_MOD, "Offline", 0))
return 0;
- DBWriteTimeTS(time(NULL), (HANDLE)wparam);
+ DBWriteTimeTS(time(NULL), hContact);
//db_set_w(hContact,S_MOD,"StatusTriger",(WORD)cws->value.wVal);
- if ( db_get_b(NULL, S_MOD, "FileOutput", 0)) FileWrite((HANDLE)wparam);
- if (prevStatus != cws->value.wVal) myPlaySound((HANDLE)wparam, cws->value.wVal, prevStatus);
+ if ( db_get_b(NULL, S_MOD, "FileOutput", 0)) FileWrite(hContact);
+ if (prevStatus != cws->value.wVal) myPlaySound(hContact, cws->value.wVal, prevStatus);
if ( db_get_b(NULL, S_MOD, "UsePopups", 0))
if (prevStatus != cws->value.wVal)
- ShowPopup((HANDLE)wparam, GetContactProto((HANDLE)wparam), cws->value.wVal|0x8000);
+ ShowPopup(hContact, GetContactProto(hContact), cws->value.wVal|0x8000);
- if ( db_get_b(NULL, S_MOD, "KeepHistory", 0)) HistoryWrite((HANDLE)wparam);
- if ( db_get_b((HANDLE)wparam, S_MOD, "OnlineAlert", 0)) ShowHistory((HANDLE)wparam, 1);
- db_set_b((HANDLE)wparam, S_MOD, "Offline", 0);
+ if ( db_get_b(NULL, S_MOD, "KeepHistory", 0)) HistoryWrite(hContact);
+ if ( db_get_b(hContact, S_MOD, "OnlineAlert", 0)) ShowHistory(hContact, 1);
+ db_set_b(hContact, S_MOD, "Offline", 0);
}
} else if (IsWatchedProtocol(cws->szModule)) {
//here we will come when <User>/<module>/Status is changed or it is idle event and if <module> is watched
- if (CallProtoService(cws->szModule,PS_GETSTATUS,0,0)>ID_STATUS_OFFLINE){
- int index;
- if (!(index = isContactQueueActive((HANDLE)wparam))) {
- index = addContactToQueue((HANDLE)wparam);
- strncpy(contactQueue[index]->sProtoName,cws->szModule,MAXMODULELABELLENGTH);
- mir_forkthread(waitThread, contactQueue[index]);
+ if ( CallProtoService(cws->szModule,PS_GETSTATUS,0,0) > ID_STATUS_OFFLINE){
+ logthread_info *p = arContacts.find((logthread_info*)&hContact);
+ if (p == NULL) {
+ p = addContactToQueue(hContact);
+ strncpy(p->sProtoName, cws->szModule, MAXMODULELABELLENGTH);
+ mir_forkthread(waitThread, p);
}
- contactQueue[index]->courStatus = isIdleEvent ? db_get_w((HANDLE)wparam, cws->szModule, "Status", ID_STATUS_OFFLINE) : cws->value.wVal;
+ p->currStatus = isIdleEvent ? db_get_w(hContact, cws->szModule, "Status", ID_STATUS_OFFLINE) : cws->value.wVal;
} }
return 0;
@@ -725,7 +703,7 @@ int ModeChange(WPARAM wparam,LPARAM lparam) logthread_info *info = (logthread_info *)malloc(sizeof(logthread_info));
strncpy(info->sProtoName,courProtoName,MAXMODULELABELLENGTH);
info->hContact = 0;
- info->courStatus = 0;
+ info->currStatus = 0;
mir_forkthread(cleanThread, info);
}
|