Removes extra debug for Outlook address book plugin. Adds a thread collector for Outlook notifications.

cusax-fix 4721
Vincent Lucas 12 years ago
parent 7b6b24ac11
commit c995a7aa40

@ -126,9 +126,6 @@ void MAPINotification_jniCallDeletedMethod(LPSTR iUnknown)
if(MAPINotification_VM
->AttachCurrentThreadAsDaemon((void**) &tmpJniEnv, NULL) == 0)
{
fprintf(stdout, "MAPINotification_jniCallDeletedMethod: id: %s\n",
iUnknown);
fflush(stdout);
jstring value = tmpJniEnv->NewStringUTF(iUnknown);
tmpJniEnv->CallVoidMethod(
@ -262,10 +259,6 @@ STDAPICALLTYPE MAPINotification_onNotify
(LPBYTE) lpNotifications[i].info.obj.lpOldID,
lpNotifications[i].info.obj.cbOldID,
oldEntryIdStr);
fprintf(stdout,
"MAPINotification_onNotify: evModified oldID: %s\n",
oldEntryIdStr);
fflush(stdout);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE
&& MAPINotification_callDeletedMethod != NULL)
{
@ -289,10 +282,6 @@ STDAPICALLTYPE MAPINotification_onNotify
lpNotifications[i].info.obj.cbEntryID,
entryIdStr);
fprintf(stdout, "MAPINotification_onNotify: evDeleted: %s\n",
entryIdStr);
fflush(stdout);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE
&& MAPINotification_callDeletedMethod != NULL)
{
@ -335,13 +324,6 @@ STDAPICALLTYPE MAPINotification_onNotify
wasteBasketProps[0].Value.bin.cb,
wasteBasketEntryIdStr);
fprintf(stdout,
"MAPINotification_onNotify: evMoved: bin %s / %s / %s\n",
entryIdStr,
parentEntryIdStr,
wasteBasketEntryIdStr);
fflush(stdout);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE
&& strcmp(parentEntryIdStr, wasteBasketEntryIdStr) == 0
&& MAPINotification_callDeletedMethod != NULL)
@ -368,10 +350,6 @@ STDAPICALLTYPE MAPINotification_onNotify
(LPBYTE) lpNotifications[i].info.obj.lpOldID,
lpNotifications[i].info.obj.cbOldID,
oldEntryIdStr);
fprintf(stdout,
"MAPINotification_onNotify: evMoved oldID: %s\n",
oldEntryIdStr);
fflush(stdout);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE
&& MAPINotification_callDeletedMethod != NULL)
{

@ -67,9 +67,6 @@ static jboolean MsOutlookAddrBookContactQuery_foreachContactInMsgStoresTable
static jboolean MsOutlookAddrBookContactQuery_foreachMailUser
(ULONG objType, LPUNKNOWN iUnknown,
const char * query, void * callback, void * callbackObject);
static jboolean MsOutlookAddrBookContactQuery_foreachMailUserInAddressBook
(LPMAPISESSION mapiSession, const char * query,
void * callback, void * callbackObject);
static jboolean MsOutlookAddrBookContactQuery_foreachMailUserInContainerTable
(LPMAPICONTAINER mapiContainer, LPMAPITABLE mapiTable,
const char * query, void * callback, void * callbackObject);
@ -397,21 +394,11 @@ void MsOutlookAddrBookContactQuery_foreachMailUser(
return;
}
jboolean proceed
= MsOutlookAddrBookContactQuery_foreachContactInMsgStoresTable(
mapiSession,
query,
callback,
callbackObject);
if(proceed)
{
MsOutlookAddrBookContactQuery_foreachMailUserInAddressBook(
mapiSession,
query,
callback,
callbackObject);
}
MsOutlookAddrBookContactQuery_foreachContactInMsgStoresTable(
mapiSession,
query,
callback,
callbackObject);
MAPISession_unlock();
}
@ -508,45 +495,6 @@ MsOutlookAddrBookContactQuery_foreachMailUser
return proceed;
}
static jboolean
MsOutlookAddrBookContactQuery_foreachMailUserInAddressBook
(LPMAPISESSION mapiSession, const char * query,
void * callback, void * callbackObject)
{
HRESULT hResult;
LPADRBOOK adrBook;
jboolean proceed = JNI_FALSE;
hResult = mapiSession->OpenAddressBook(0, NULL, AB_NO_DIALOG, &adrBook);
if (HR_SUCCEEDED(hResult))
{
ULONG objType;
LPUNKNOWN iUnknown;
hResult = adrBook->OpenEntry(
0,
NULL,
NULL,
MsOutlookAddrBookContactQuery_openEntryUlFlags,
&objType,
&iUnknown);
if (HR_SUCCEEDED(hResult))
{
proceed
= MsOutlookAddrBookContactQuery_foreachMailUser(
objType, iUnknown,
query, callback, callbackObject);
iUnknown->Release();
}
adrBook->Release();
}
return proceed;
}
static jboolean
MsOutlookAddrBookContactQuery_foreachMailUserInContainerTable
(LPMAPICONTAINER mapiContainer, LPMAPITABLE mapiTable,
@ -1937,19 +1885,6 @@ int MsOutlookAddrBookContactQuery_compareEntryIds(
}
result = res;
}
if(strcmp(id1, id2) == 0)
{
fprintf(stderr,
"CHENZO compareEntryIds: \
\n\tid1: %s\
\n\tid2: %s\
\n\tresult: %d\n",
id1,
id2,
result);
fflush(stderr);
}
mapiId1->Release();
MAPIFreeBuffer(contactId1.lpb);
mapiId2->Release();

@ -124,9 +124,6 @@ HRESULT STDMETHODCALLTYPE MsOutlookAddrBookClient::foreachMailUserCallback(
HRESULT STDMETHODCALLTYPE MsOutlookAddrBookClient::deleted(BSTR id)
{
char * charId = StringUtils::WideCharToMultiByte(id);
fprintf(stdout, "MsOutlookAddrBookClient_deleted: id: %s\n",
charId);
fflush(stdout);
MAPINotification_jniCallDeletedMethod(charId);
free(charId);

@ -130,9 +130,6 @@ void waitParentProcessStop()
static void Server_deleted(LPSTR id)
{
HRESULT hr = E_FAIL;
fprintf(stdout, "Server_deleted: id: %s\n",
id);
fflush(stdout);
IMsOutlookAddrBookClient * msOutlookAddrBookClient = NULL;
if((hr = CoCreateInstance(

@ -381,10 +381,6 @@ public MsOutlookAddrBookContactQuery(
Pattern query)
{
super(msoabcss, query);
if(logger.isDebugEnabled())
{
logger.debug("Creating new query: " + query.toString());
}
}
/**
@ -883,11 +879,6 @@ && matches(propIndex, (String) prop)
if (matches)
{
if(logger.isDebugEnabled())
{
logger.debug("Contact matches: " + id
+ ", displayName: " + getDisplayName(props));
}
List<ContactDetail> contactDetails = getContactDetails(props);
// What's the point of showing a contact who has no contact details?
@ -1004,10 +995,6 @@ public static List<ContactDetail> getContactDetails(Object[] values)
@Override
protected void run()
{
if(logger.isDebugEnabled())
{
logger.debug("run query: " + query.toString());
}
synchronized (MsOutlookAddrBookContactQuery.class)
{
foreachMailUser(
@ -1023,10 +1010,6 @@ protected void run()
*/
public void inserted(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("inserted: " + id);
}
SourceContact sourceContact = findSourceContactByID(id);
if(sourceContact != null
&& sourceContact instanceof MsOutlookAddrBookSourceContact)
@ -1059,10 +1042,6 @@ public void inserted(String id)
*/
public void updated(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("updated: " + id);
}
SourceContact sourceContact = findSourceContactByID(id);
if(sourceContact != null
&& sourceContact instanceof MsOutlookAddrBookSourceContact)
@ -1083,10 +1062,6 @@ public void updated(String id)
*/
public void deleted(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("deleted: " + id);
}
if(id != null)
{
SourceContact sourceContact = findSourceContactByID(id);
@ -1139,10 +1114,6 @@ boolean callback(String id)
*/
public void addEmptyContact(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("Add empty contact: " + id);
}
if(id != null)
{
final MsOutlookAddrBookSourceContact sourceContact

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.plugin.addrbook.msoutlook;
import java.util.*;
import java.util.regex.*;
import net.java.sip.communicator.plugin.addrbook.*;
@ -51,6 +52,16 @@ public class MsOutlookAddrBookContactSourceService
private static final long MAPI_MULTITHREAD_NOTIFICATIONS = 0x00000001;
/**
* The thread used to collect the notifications.
*/
private NotificationThread notificationThread = null;
/**
* The mutex used to synchronized the notification thread.
*/
private Object notificationThreadMutex = new Object();
/**
* The latest query created.
*/
@ -209,12 +220,8 @@ public class NotificationsDelegate
*/
public void inserted(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("Inserted: " + id);
}
if(latestQuery != null)
latestQuery.inserted(id);
addNotification(id, 'i');
}
/**
@ -222,12 +229,8 @@ public void inserted(String id)
*/
public void updated(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("Updated: " + id);
}
if(latestQuery != null)
latestQuery.updated(id);
addNotification(id, 'u');
}
/**
@ -235,12 +238,8 @@ public void updated(String id)
*/
public void deleted(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("Deleted: " + id);
}
if(latestQuery != null)
latestQuery.deleted(id);
addNotification(id, 'd');
}
}
@ -263,10 +262,6 @@ public String createContact()
*/
public void addEmptyContact(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("Add empty contact: " + id);
}
if(id != null && latestQuery != null)
{
latestQuery.addEmptyContact(id);
@ -281,10 +276,6 @@ public void addEmptyContact(String id)
*/
public void deleteContact(String id)
{
if(logger.isDebugEnabled())
{
logger.debug("Delete contact: " + id);
}
if(id != null && MsOutlookAddrBookContactQuery.deleteContact(id))
{
if(latestQuery != null)
@ -309,4 +300,191 @@ public boolean canBeUsedToSearchContacts()
return !AddrBookActivator.getConfigService().getBoolean(
PNAME_OUTLOOK_ADDR_BOOK_SEARCH_FIELD_DISABLED, false);
}
/**
* Collects a new notification and adds it to the notification thread.
*
* @param id The contact id.
* @param function The kind of notification: 'd' for deleted, 'u' for
* updated and 'i' for inserted.
*/
public void addNotification(String id, char function)
{
synchronized(notificationThreadMutex)
{
if(notificationThread == null
|| !notificationThread.isAlive())
{
notificationThread = new NotificationThread();
notificationThread.start();
}
notificationThread.add(id, function);
}
}
/**
* Thread used to collect the notification.
*/
private class NotificationThread
extends Thread
{
/**
* The list of notification collected.
*/
private Vector<NotificationIdFunction> contactIds
= new Vector<NotificationIdFunction>();
/**
* Initializes a new notification thread.
*/
public NotificationThread()
{
super("MsOutlookAddrbookContactSourceService notification thread");
}
/**
* Dispatchs the collected notifications.
*/
public void run()
{
boolean hasMore = false;
NotificationIdFunction idFunction = null;
String id;
char function;
synchronized(notificationThreadMutex)
{
hasMore = (contactIds.size() > 0);
if(hasMore)
{
idFunction = contactIds.remove(0);
}
}
while(hasMore)
{
if(latestQuery != null)
{
id = idFunction.getId();
function = idFunction.getFunction();
if(function == 'd')
{
latestQuery.deleted(id);
}
else if(function == 'u')
{
latestQuery.updated(id);
}
else if(function == 'i')
{
latestQuery.inserted(id);
}
}
synchronized(notificationThreadMutex)
{
hasMore = (contactIds.size() > 0);
if(hasMore)
{
idFunction = contactIds.remove(0);
}
}
}
}
/**
* Adds a new notification. Avoids previous notification for the given
* contact.
*
* @param id The contact id.
* @param function The kind of notification: 'd' for deleted, 'u' for
* updated and 'i' for inserted.
*/
public void add(String id, char function)
{
NotificationIdFunction idFunction
= new NotificationIdFunction(id, function);
synchronized(notificationThreadMutex)
{
contactIds.remove(idFunction);
contactIds.add(idFunction);
}
}
}
/**
* Defines a notification: a combination of a contact identifier and a
* function.
*/
private class NotificationIdFunction
{
/**
* The contact identifier.
*/
private String id;
/**
* The kind of notification: 'd' for deleted, 'u' for updated and 'i'
* for inserted.
*/
private char function;
/**
* Creates a new notification.
*
* @param id The contact id.
* @param function The kind of notification: 'd' for deleted, 'u' for
* updated and 'i' for inserted.
*/
public NotificationIdFunction(String id, char function)
{
this.id = id;
this.function = function;
}
/**
* Returns the contact identifier.
*
* @return The contact identifier.
*/
public String getId()
{
return this.id;
}
/**
* Returns the kind of notification.
*
* @return 'd' for deleted, 'u' for updated and 'i' for inserted.
*/
public char getFunction()
{
return this.function;
}
/**
* Returns if this notification is about the same contact has the one
* given in parameter.
*
* @param obj An NotificationIdFunction to compare with.
*
* @return True if this notification is about the same contact has the
* one given in parameter. False otherwise.
*/
public boolean equals(Object obj)
{
return (this.id == null && obj == null
|| obj instanceof String && this.id.equals((String) obj));
}
/**
* Returns the hash code corresponding to the contact identifier.
*
* @return The hash code corresponding to the contact identifier.
*/
public int hashCode()
{
return this.id.hashCode();
}
}
}

Loading…
Cancel
Save