From 194ecda7bc5cbc440475ecb2a76d4d66a19cccf8 Mon Sep 17 00:00:00 2001 From: "daniel.boelzle%sun.com" Date: Mon, 20 Aug 2007 16:37:25 +0000 Subject: [PATCH] Bug 329034 - async calICalendar methods and callbacks need request handles or ids; r=lilmatt,philipp git-svn-id: svn://10.0.0.236/trunk@232389 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/calendar/base/public/Makefile.in | 1 + mozilla/calendar/base/public/calICalendar.idl | 34 +++++-- .../public/calIOperation.idl} | 45 ++++----- .../sun-calendar-event-dialog-freebusy.xml | 2 +- .../providers/wcap/calWcapCalendarItems.js | 7 +- .../calendar/providers/wcap/calWcapRequest.js | 36 ++++--- .../calendar/providers/wcap/calWcapSession.js | 8 +- .../providers/wcap/public/Makefile.in | 1 - .../wcap/public/calIWcapCalendar.idl | 97 +++++++++---------- .../providers/wcap/public/calIWcapSession.idl | 24 ++--- 10 files changed, 134 insertions(+), 121 deletions(-) rename mozilla/calendar/{providers/wcap/public/calIWcapRequest.idl => base/public/calIOperation.idl} (73%) diff --git a/mozilla/calendar/base/public/Makefile.in b/mozilla/calendar/base/public/Makefile.in index 7a97af86664..9a9531d8874 100644 --- a/mozilla/calendar/base/public/Makefile.in +++ b/mozilla/calendar/base/public/Makefile.in @@ -79,6 +79,7 @@ XPIDLSRCS = calIAlarmService.idl \ calIWeekTitleService.idl \ calIPrintFormatter.idl \ calITransactionManager.idl \ + calIOperation.idl \ $(NULL) EXPORTS = calBaseCID.h diff --git a/mozilla/calendar/base/public/calICalendar.idl b/mozilla/calendar/base/public/calICalendar.idl index 27dd77794cb..d72dd4f4e91 100644 --- a/mozilla/calendar/base/public/calICalendar.idl +++ b/mozilla/calendar/base/public/calICalendar.idl @@ -53,6 +53,7 @@ interface calIObserver; interface calIOperationListener; interface calIRange; interface calIDateTime; +interface calIOperation; [scriptable, uuid(74e685e4-d863-11d9-88f2-000b7d081f44)] interface calICalendar : nsISupports @@ -147,6 +148,7 @@ interface calICalendar : nsISupports * * @param aItem item to add * @param aListener where to call back the results + * @return optional operation handle to track the operation * * - If aItem already has an ID, that ID is used when adding. * - If aItem is mutable and has no ID, the calendar is expected @@ -167,7 +169,8 @@ interface calICalendar : nsISupports * and aDetail set with the calIItemBase of the internal already * existing item. */ - void addItem( in calIItemBase aItem, in calIOperationListener aListener ); + calIOperation addItem(in calIItemBase aItem, + in calIOperationListener aListener); /** * adoptItem adds the given calIItemBase to the calendar, but doesn't @@ -177,7 +180,8 @@ interface calICalendar : nsISupports * * @see addItem */ - void adoptItem( in calIItemBase aItem, in calIOperationListener aListener ); + calIOperation adoptItem(in calIItemBase aItem, + in calIOperationListener aListener); /** * modifyItem takes a modified mutable item and modifies the @@ -195,6 +199,7 @@ interface calICalendar : nsISupports * @param aNewItem new version to replace the old one * @param aOldItem caller's view of the item to be changed, as it is now * @param aListener where to call back the results + * @return optional operation handle to track the operation * * The results of the operation are reported through an * onOperationComplete call on the listener, with the following @@ -205,8 +210,9 @@ interface calICalendar : nsISupports * - aDetail: the calIItemBase corresponding to the newly-updated * immutable version of the modified item */ - void modifyItem( in calIItemBase aNewItem, in calIItemBase aOldItem, - in calIOperationListener aListener ); + calIOperation modifyItem(in calIItemBase aNewItem, + in calIItemBase aOldItem, + in calIOperationListener aListener); /** * deleteItem takes an item that is to be deleted. The item is @@ -216,6 +222,7 @@ interface calICalendar : nsISupports * * @param aItem item to delete * @param aListener where to call back the results + * @return optional operation handle to track the operation * * The results of the operation are reported through an * onOperationComplete call on the listener, with the following @@ -226,7 +233,8 @@ interface calICalendar : nsISupports * - aDetail: the calIItemBase corresponding to the immutable version * of the deleted item */ - void deleteItem( in calIItemBase aItem, in calIOperationListener aListener ); + calIOperation deleteItem(in calIItemBase aItem, + in calIOperationListener aListener); /** * Get a single event. The event will be typed as one of the subclasses @@ -234,6 +242,7 @@ interface calICalendar : nsISupports * * @param aId UID of the event * @param aListener listener to which this event will be called back. + * @return optional operation handle to track the operation * * The results of the operation are reported through the listener, * via zero or one onGetResult calls (with aCount set to 1) @@ -245,7 +254,7 @@ interface calICalendar : nsISupports * - aId: the ID of the requested item * - aDetail: null (? we can also pass the item back here as well,..) */ - void getItem( in string aId, in calIOperationListener aListener ); + calIOperation getItem(in string aId, in calIOperationListener aListener); /** * XXX As mentioned above, this method isn't suitably general. It's just @@ -283,6 +292,7 @@ interface calICalendar : nsISupports * @param aRangeEndEx Items starting before (not including) aRangeEndEx should be * returned. If null, assume "until the end of time". * @param aListener The results will be called back through this interface. + * @return optional operation handle to track the operation * * * The results of the operation are reported through the listener, @@ -294,9 +304,11 @@ interface calICalendar : nsISupports * - aId: null * - aDetail: null */ - void getItems( in unsigned long aItemFilter, in unsigned long aCount, - in calIDateTime aRangeStart, in calIDateTime aRangeEndEx, - in calIOperationListener aListener ); + calIOperation getItems(in unsigned long aItemFilter, + in unsigned long aCount, + in calIDateTime aRangeStart, + in calIDateTime aRangeEndEx, + in calIOperationListener aListener); /** * Whether or not alarms for this calendar should be suppressed. @@ -315,8 +327,10 @@ interface calICalendar : nsISupports * Refresh the datasource, and call the observers for any changes found. * If the provider doesn't know the details of the changes it must call * onLoad on its observers. + * + * @return optional operation handle to track the operation */ - void refresh(); + calIOperation refresh(); /** * Turn on batch mode. Observers will get a notification of this. diff --git a/mozilla/calendar/providers/wcap/public/calIWcapRequest.idl b/mozilla/calendar/base/public/calIOperation.idl similarity index 73% rename from mozilla/calendar/providers/wcap/public/calIWcapRequest.idl rename to mozilla/calendar/base/public/calIOperation.idl index d33e955cb29..6f0de495d53 100755 --- a/mozilla/calendar/providers/wcap/public/calIWcapRequest.idl +++ b/mozilla/calendar/base/public/calIOperation.idl @@ -1,4 +1,3 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -38,49 +37,45 @@ #include "nsIVariant.idl" -[scriptable, uuid(6586B48D-3FF6-4b82-B9F6-5B561D416E36)] -interface calIWcapRequest : nsISupports +[scriptable, uuid(B96C2997-7AAA-4619-AD48-B7EBD9236C93)] +interface calIOperation : nsISupports { /** - * For easy testing for equality. + * Id for easy management of pending requests. */ - readonly attribute unsigned long id; - + readonly attribute AUTF8String id; + /** * Determines whether the request is pending, i.e. has not been completed. */ readonly attribute boolean isPending; - - /** - * Determines whether the request has succeeded, i.e. it has successfully - * been completed. - * XXX todo: remove this and favor - * !request.isPending && Components.isSuccessCode(request.status) ? - */ - readonly attribute boolean succeeded; - + /** * Status of the request, e.g. NS_OK while pending or after successful * completion, or NS_ERROR_FAILED when failed. */ readonly attribute nsIVariant status; - + + /** + * Determines whether the request has succeeded, i.e. it has successfully + * been completed. + */ + readonly attribute boolean success; + /** * Cancels a pending request and changes status. */ - void cancel(in nsIVariant status); + void cancel(in nsIVariant aStatus); }; -[scriptable, uuid(D0BC007F-D0B5-4352-A32A-8F7A9F55A713)] -interface calIWcapRequestResultListener : nsISupports +[scriptable, uuid(1FA39726-63D2-440c-A464-296D2822B9DA)] +interface calIGenericOperationListener : nsISupports { /** - * Callback receiving results. + * Generic callback receiving result. * - * @param request object to track operation - * @param result request result or null in case of an error + * @param aOperation operation object + * @param aResult result or null in case of an error */ - void onRequestResult(in calIWcapRequest request, - in nsIVariant result); + void onResult(in calIOperation aOperation, in nsIVariant aResult); }; - diff --git a/mozilla/calendar/prototypes/wcap/sun-calendar-event-dialog-freebusy.xml b/mozilla/calendar/prototypes/wcap/sun-calendar-event-dialog-freebusy.xml index 13e1fb93ae6..d6267fe7c4b 100644 --- a/mozilla/calendar/prototypes/wcap/sun-calendar-event-dialog-freebusy.xml +++ b/mozilla/calendar/prototypes/wcap/sun-calendar-event-dialog-freebusy.xml @@ -1174,7 +1174,7 @@ return this; }, - onRequestResult: function mFBL_onRequestResult(request, entries) { + onResult: function mFBL_onResult(request, entries) { // Delegate to the binding this.binding.onFreeBusy(request, entries); } diff --git a/mozilla/calendar/providers/wcap/calWcapCalendarItems.js b/mozilla/calendar/providers/wcap/calWcapCalendarItems.js index 2c072f6fca3..eb438182757 100644 --- a/mozilla/calendar/providers/wcap/calWcapCalendarItems.js +++ b/mozilla/calendar/providers/wcap/calWcapCalendarItems.js @@ -1194,10 +1194,9 @@ function calWcapCalendar_getItems(itemFilter, maxResults, rangeStart, rangeEnd, (itemFilter & calICalendar.ITEM_FILTER_TYPE_EVENT) && rangeStart && rangeEnd) { - var freeBusyListener = { // calIWcapRequestResultListener: - onRequestResult: - function freeBusyListener_onRequestResult(request, result) { - if (!request.succeeded) + var freeBusyListener = { // calIGenericOperationListener: + onResult: function freeBusyListener_onResult(request, result) { + if (!request.success) throw request.status; var items = []; for each (var period in result) { diff --git a/mozilla/calendar/providers/wcap/calWcapRequest.js b/mozilla/calendar/providers/wcap/calWcapRequest.js index 9ef12b3089b..40bbcf8a70f 100644 --- a/mozilla/calendar/providers/wcap/calWcapRequest.js +++ b/mozilla/calendar/providers/wcap/calWcapRequest.js @@ -37,8 +37,6 @@ * ***** END LICENSE BLOCK ***** */ /** - Requests, either the queued calWcapRequest or an async network request. - A request object is used to track an async action. While the action is running, isPending is true. Functions issuing an async action usually take a response function along @@ -48,15 +46,19 @@ The response function gets the ended request as first parameter to check whether the request has been successful and get its data. The request function itself may return either - - a further calIWcapRequest request object, i.e. an async continuation + - a further calIOperation request object, i.e. an async continuation - some data (incl null/undefined) which is the result of the async function, indicating that there is no further continuation */ +var g_requestPrefix = null; var g_requestId = 0; function generateRequestId() { + if (!g_requestPrefix) { + g_requestPrefix = (getUUID() + "-"); + } ++g_requestId; - return g_requestId; + return (g_requestPrefix + g_requestId); } function calWcapRequest(respFunc, logContext) { @@ -190,14 +192,14 @@ calWcapRequest.prototype = { } }, - // calIWcapRequest: + // calIOperation: get id() { return this.m_id; }, get isPending() { return this.m_isPending; }, - get succeeded() { + get success() { return (!this.isPending && Components.isSuccessCode( getResultCode(this.status) )); }, get status() { @@ -220,14 +222,12 @@ calWcapRequest.prototype = { }; function calWcapNetworkRequest(channel, respFunc, bLogging) { -// this.superClass(respFunc); this.wrappedJSObject = this; this.m_id = generateRequestId(); this.m_channel = channel; this.m_respFunc = respFunc; this.m_bLogging = (bLogging === undefined ? true : bLogging); } -// subClass(calWcapNetworkRequest, calWcapRequest); calWcapNetworkRequest.prototype = { m_id: 0, @@ -235,9 +235,6 @@ calWcapNetworkRequest.prototype = { m_respFunc: null, m_bLogging: false, - m_isPending: true, - get isPending() { return this.m_isPending; }, - toString: function calWcapNetworkRequest_toString() { var ret = ("calWcapNetworkRequest id=" + this.id + ", parent-id=" + @@ -255,11 +252,22 @@ calWcapNetworkRequest.prototype = { this.detachFromParent(); // detach without error return (this.m_parentRequest = req); }, - + + // calIOperation: get id() { return this.m_id; }, + m_isPending: true, + get isPending() { return this.m_isPending; }, + + get success() { + return (!this.isPending && Components.isSuccessCode( getResultCode(this.status) )); + }, + get status() { + return this.m_channel.status; + }, + detachFromParent: function calWcapNetworkRequest_detachFromParent(err) { var parentRequest = this.m_parentRequest; if (parentRequest) { @@ -276,7 +284,7 @@ calWcapNetworkRequest.prototype = { this.detachFromParent(); // detach without error // xxx todo: check whether this works on redirected channels! if (this.m_channel.isPending()) { - log("cancelling netwerk request...", this); + log("canceling netwerk request...", this); this.m_channel.cancel(NS_BINDING_FAILED); } } @@ -385,7 +393,7 @@ function issueNetworkRequest(parentRequest, respFunc, url, bLogging) } } -function getWcapRequestStatusString( xml ) +function getWcapRequestStatusString(xml) { var str = "request status: "; var items = xml.getElementsByTagName("RSTATUS"); diff --git a/mozilla/calendar/providers/wcap/calWcapSession.js b/mozilla/calendar/providers/wcap/calWcapSession.js index 2c012ded61b..e781874e665 100644 --- a/mozilla/calendar/providers/wcap/calWcapSession.js +++ b/mozilla/calendar/providers/wcap/calWcapSession.js @@ -387,7 +387,7 @@ calWcapSession.prototype = { else log("logout succeeded.", this_); if (listener) - listener.onRequestResult(request, err); + listener.onResult(request, err); }, log("logout", this)); @@ -663,7 +663,7 @@ calWcapSession.prototype = { for (var calId in calIds) { if (!this_.m_subscribedCals[calId]) { var listener = { - onRequestResult: function search_onRequestResult(request, result) { + onResult: function search_onResult(request, result) { try { if (!request.succeeded) throw request.status; @@ -894,7 +894,7 @@ calWcapSession.prototype = { if (err) this_.notifyError(err); if (listener) - listener.onRequestResult(request, data); + listener.onResult(request, data); }, log("searchForCalendars, searchString=" + searchString, this)); @@ -1003,7 +1003,7 @@ calWcapSession.prototype = { break; } if (listener) - listener.onRequestResult(request, data); + listener.onResult(request, data); }, log("getFreeBusyTimes():\n\tcalId=" + calId + "\n\trangeStart=" + zRangeStart + ",\n\trangeEnd=" + zRangeEnd, this)); diff --git a/mozilla/calendar/providers/wcap/public/Makefile.in b/mozilla/calendar/providers/wcap/public/Makefile.in index 1b949b1e4a6..5a43cb73228 100644 --- a/mozilla/calendar/providers/wcap/public/Makefile.in +++ b/mozilla/calendar/providers/wcap/public/Makefile.in @@ -48,7 +48,6 @@ XPIDL_MODULE = wcap XPIDLSRCS = calIWcapCalendar.idl \ calIWcapSession.idl \ calIWcapErrors.idl \ - calIWcapRequest.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/calendar/providers/wcap/public/calIWcapCalendar.idl b/mozilla/calendar/providers/wcap/public/calIWcapCalendar.idl index 5fb54b94e09..3fbfccace8c 100644 --- a/mozilla/calendar/providers/wcap/public/calIWcapCalendar.idl +++ b/mozilla/calendar/providers/wcap/public/calIWcapCalendar.idl @@ -38,7 +38,7 @@ #include "calICalendar.idl" #include "calIDateTime.idl" -#include "calIWcapRequest.idl" +#include "calIOperation.idl" interface calIWcapSession; interface calIAttendee; @@ -117,7 +117,6 @@ interface calIWcapCalendar : calICalendar * @param propName property name (e.g. X-S1CS-CALPROPS-COMMON-NAME) * @param count length of props array * @param listener called with array of strings as result - * @return request object to track operation * @exception NS_ERROR_NOT_AVAILABLE if not logged in */ void getCalendarProperties(in string propName, @@ -218,13 +217,11 @@ interface calIWcapCalendar : calICalendar * @param listener operation listener for SYNC operation * (may optionally implemented calIObserver to receive * onAddItem(), onModifyItem() or onDeleteItem() calls) - * @return request object to track operation */ - calIWcapRequest syncChangesTo( - in calICalendar destCal, - in unsigned long itemFilter, - in calIDateTime dtFrom, - in calIOperationListener listener); + calIOperation syncChangesTo(in calICalendar destCal, + in unsigned long itemFilter, + in calIDateTime dtFrom, + in calIOperationListener listener); /* xxx todo: separate out into another interface and leave only an attribute @@ -307,47 +304,47 @@ interface calIWcapCalendar : calICalendar */ boolean checkAccess(in unsigned long accessControlBits); - /** - * Defines granted and denied permissions for a specific user or - * user domain. Specific user entries precede over domain entries. - * - * Examples: - * a) Allow all users availability and read access, - * but jdoe only availability access: - * defineAccessControl("@", AC_FREEBUSY | AC_COMP_READ); - * defineAccessControl("jdoe", AC_FREEBUSY); - * - * b) Restrict jdoe to have no access: - * defineAccessControl("jdoe", 0); - * - * Follow-up definition calls for the same user will overwrite previous - * definitions. - * - * @param userId user that is affected by the access control bits - * WCAP specific: - * - @ stands in for everybody - * xxx todo: change the above - * @param accessControlBits access control bits (above AC_ definitions) - * @param listener called when access control bits have been updated - * @return request object to track operation - */ - calIWcapRequest defineAccessControl( - in string userId, in unsigned long accessControlBits, - in calIWcapRequestResultListener listener); +// /** +// * Defines granted and denied permissions for a specific user or +// * user domain. Specific user entries precede over domain entries. +// * +// * Examples: +// * a) Allow all users availability and read access, +// * but jdoe only availability access: +// * defineAccessControl("@", AC_FREEBUSY | AC_COMP_READ); +// * defineAccessControl("jdoe", AC_FREEBUSY); +// * +// * b) Restrict jdoe to have no access: +// * defineAccessControl("jdoe", 0); +// * +// * Follow-up definition calls for the same user will overwrite previous +// * definitions. +// * +// * @param userId user that is affected by the access control bits +// * WCAP specific: +// * - @ stands in for everybody +// * xxx todo: change the above +// * @param accessControlBits access control bits (above AC_ definitions) +// * @param listener called when access control bits have been updated +// * @return optional object to track operation +// */ +// calIOperation defineAccessControl( +// in string userId, in unsigned long accessControlBits, +// in calIGenericOperationListener listener); - /** - * To reset a user's access control definition to the default ones - * that everybody is granted. - * In case the user has no specific access control definition, - * Components.results.NS_ERROR_INVALID_ARG is thrown. - * - * @param userId user id - * @param listener called when access control bits have been updated - * @return request object to track operation - */ - calIWcapRequest resetAccessControl( - in string userId, - in calIWcapRequestResultListener listener); +// /** +// * To reset a user's access control definition to the default ones +// * that everybody is granted. +// * In case the user has no specific access control definition, +// * Components.results.NS_ERROR_INVALID_ARG is thrown. +// * +// * @param userId user id +// * @param listener called when access control bits have been updated +// * @return optional object to track operation +// */ +// calIOperation resetAccessControl( +// in string userId, +// in calIGenericOperationListener listener); // /** // * Gets the set of access control definitions (including "everybody"). @@ -357,9 +354,9 @@ interface calIWcapCalendar : calICalendar // * @param users users ids // * @param accessControlBits access control bits // * @param listener called with xxx todo -// * @return request object to track operation +// * @return optional object to track operation // */ -// calIWcapRequest getAccessControlDefinitions( +// calIOperation getAccessControlDefinitions( // out unsigned long count, // [array, size_is(count)] out string users, // [array, size_is(count)] out unsigned long accessControlBits ); diff --git a/mozilla/calendar/providers/wcap/public/calIWcapSession.idl b/mozilla/calendar/providers/wcap/public/calIWcapSession.idl index aea4c3400b7..dce33566f88 100755 --- a/mozilla/calendar/providers/wcap/public/calIWcapSession.idl +++ b/mozilla/calendar/providers/wcap/public/calIWcapSession.idl @@ -39,7 +39,7 @@ #include "calIWcapCalendar.idl" #include "calIDateTime.idl" -#include "calIWcapRequest.idl" +#include "calIOperation.idl" /** * WCAP session. @@ -94,12 +94,12 @@ interface calIWcapSession : nsISupports * @param maxResults maximum number of results * (0 means default, e.g. 200 with respect to Sun calendar servers) * @param listener listener called with an array of calIWcapCalendar objects - * @return request object to track operation + * @return optional object to track operation */ - calIWcapRequest searchForCalendars(in string searchString, - in unsigned long searchOptions, - in unsigned long maxResults, - in calIWcapRequestResultListener listener); + calIOperation searchForCalendars(in string searchString, + in unsigned long searchOptions, + in unsigned long maxResults, + in calIGenericOperationListener listener); /* xxx todo freebusy: separate into own interface? */ /** @@ -111,12 +111,12 @@ interface calIWcapSession : nsISupports * @param rangeEnd end time of free-busy search * @param bBusy whether to return busy entries or free entries * @param listener called with an array of calIPeriod objects - * @return request object to track operation + * @return optional object to track operation */ - calIWcapRequest getFreeBusyTimes(in string calId, - in calIDateTime rangeStart, - in calIDateTime rangeEnd, - in boolean bBusy, - in calIWcapRequestResultListener listener); + calIOperation getFreeBusyTimes(in string calId, + in calIDateTime rangeStart, + in calIDateTime rangeEnd, + in boolean bBusy, + in calIGenericOperationListener listener); };