sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * RUpsManagement implementation. See class and function definitions sl@0: * for more detail. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "upscommon.h" sl@0: #include sl@0: sl@0: namespace UserPromptService sl@0: { sl@0: EXPORT_C RUpsManagement::RUpsManagement() sl@0: /** sl@0: This constructor provides a single point of definition from sl@0: which the superclass constructor is called. sl@0: */ sl@0: : RScsClientBase(), iCreateViewFilterBuf(), iMatchLengthBuf() sl@0: { sl@0: iMatchLengthBuf() = 0; sl@0: } sl@0: sl@0: EXPORT_C TInt RUpsManagement::Connect() sl@0: /** sl@0: Connect to the UPS server. sl@0: sl@0: @return Symbian OS error code where KErrNone indicates sl@0: success and any other value indicates failure. sl@0: */ sl@0: { sl@0: TVersion v = UserPromptService::Version(); sl@0: TUidType serverFullUid = UserPromptService::ServerImageFullUid(); sl@0: sl@0: TInt r = RScsClientBase::Connect( sl@0: UserPromptService::KUpsServerName, v, UserPromptService::KServerImageName, serverFullUid); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::Close() sl@0: /** sl@0: Cleanup and call RScsClientBase::Close sl@0: */ sl@0: { sl@0: RScsClientBase::Close(); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::DeleteDatabaseL() sl@0: /** sl@0: Deletes all stored UPS decisions. sl@0: sl@0: @capability WriteDeviceData sl@0: */ sl@0: { sl@0: User::LeaveIfError(CallSessionFunction(EDeleteDatabase)); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::CreateView(const CDecisionFilter& aFilter, TRequestStatus &aStatus) sl@0: /** sl@0: Creates a view for records which match the supplied CDecisionFilter. sl@0: sl@0: If the CDecisionFilter is created using the constructor which specifies all fields (or all fields are set), then an exact match will be sl@0: searched for. sl@0: If the CDecisionFilter is created without parameters, then any fields which are not set will match any record. sl@0: sl@0: Only one view can be active in a single RUpsManagement session at any one time. sl@0: sl@0: Simultaneous database updates, either from this management session, another session or the main UPS sl@0: operation may cause the query to be aborted with KErrAbort. sl@0: sl@0: When you are finished with the view you should call CancelAndCloseView (otherwise you sl@0: will not be able to create a new view). sl@0: sl@0: @param aFilter Specifies the filter to be matched. sl@0: @capability ReadDeviceData sl@0: */ sl@0: { sl@0: aStatus = KRequestPending; sl@0: TRAPD(err, sl@0: RNullWriteStream nullstream; sl@0: nullstream << aFilter; sl@0: nullstream.CommitL(); sl@0: TInt bytesWritten = nullstream.BytesWritten(); sl@0: sl@0: iCreateViewFilterBuf.Close(); sl@0: iCreateViewFilterBuf.CreateL(bytesWritten); sl@0: sl@0: // Arg 0 - The CDecisionFilter sl@0: // Externalize to iCreateViewFilterBuf sl@0: RDesWriteStream desstream(iCreateViewFilterBuf); sl@0: CleanupClosePushL(desstream); sl@0: desstream << aFilter; sl@0: desstream.CommitL(); sl@0: CleanupStack::PopAndDestroy(&desstream); sl@0: sl@0: // Arg 1 - TUint32 length of first match returned by server sl@0: // Server writes into iMatchLengthBuf sl@0: CallSessionFunction(ECreateView, TIpcArgs(&iCreateViewFilterBuf, &iMatchLengthBuf), aStatus); sl@0: ); sl@0: if(err != KErrNone) sl@0: { sl@0: TRequestStatus *rs = &aStatus; sl@0: User::RequestComplete(rs, err); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C CDecisionRecord *RUpsManagement::NextMatchL() sl@0: /** sl@0: Returns the next matching record in the view created with CreateViewL. sl@0: sl@0: Simultaneous database updates, either from this management session, another session or the main UPS sl@0: operation may cause the query to be aborted with KErrAbort. sl@0: sl@0: When you are finished with the view you should call CancelAndCloseView. sl@0: sl@0: @return record ptr, or 0 if there are no more matching records. Leaves for other errors. sl@0: sl@0: @capability ReadDeviceData sl@0: */ sl@0: { sl@0: if(iMatchLengthBuf() == 0) sl@0: { sl@0: return 0; // No more matches sl@0: } sl@0: sl@0: CDecisionRecord *record = CDecisionRecord::NewLC(); sl@0: sl@0: // Arg 0 - The CDecisionRecord buffer sl@0: RBuf8 buf; sl@0: CleanupClosePushL(buf); sl@0: buf.CreateL(iMatchLengthBuf()); sl@0: sl@0: // Arg 1 - TUint32 length of next match sl@0: sl@0: User::LeaveIfError(CallSessionFunction(ENextMatch, TIpcArgs(&buf, &iMatchLengthBuf))); sl@0: sl@0: RDesReadStream readStream(buf); sl@0: CleanupClosePushL(readStream); sl@0: sl@0: readStream >> *record; sl@0: sl@0: CleanupStack::PopAndDestroy(&readStream); sl@0: CleanupStack::PopAndDestroy(&buf); sl@0: CleanupStack::Pop(record); sl@0: return record; sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::CancelAndCloseView() sl@0: /** sl@0: Close down a view. This can also be used to cancel an outstanding CreateView request. sl@0: sl@0: @capability ReadDeviceData sl@0: */ sl@0: { sl@0: CancelSessionFunction(ECreateView); sl@0: (void) CallSessionFunction(ECloseView); sl@0: iCreateViewFilterBuf.Close(); sl@0: iMatchLengthBuf() = 0; sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::RemoveDecisionsL(const CDecisionFilter& aFilter) sl@0: /** sl@0: Removes all records which match the supplied CDecisionFilter. sl@0: sl@0: The filter can match/delete multiple records in one operation. sl@0: sl@0: @param aFilter Specifies the records to be deleted. sl@0: sl@0: @capability WriteDeviceData sl@0: */ sl@0: { sl@0: // Calculate the buffer length required to represent the filter object sl@0: RNullWriteStream nullstream; sl@0: nullstream << aFilter; sl@0: nullstream.CommitL(); sl@0: TInt bytesWritten = nullstream.BytesWritten(); sl@0: sl@0: // Create buffer for filter sl@0: RBuf8 filterBuf; sl@0: CleanupClosePushL(filterBuf); sl@0: filterBuf.CreateL(bytesWritten); sl@0: sl@0: // Arg 0 - The CDecisionFilter sl@0: // Externalize to iCreateViewFilterBuf sl@0: RDesWriteStream desstream(filterBuf); sl@0: CleanupClosePushL(desstream); sl@0: desstream << aFilter; sl@0: desstream.CommitL(); sl@0: CleanupStack::PopAndDestroy(&desstream); sl@0: sl@0: User::LeaveIfError(CallSessionFunction(ERemoveDecisions, TIpcArgs(&filterBuf))); sl@0: sl@0: CleanupStack::PopAndDestroy(&filterBuf); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::UpdateDecision(TUint32 aRecordId, TBool aAllow, TRequestStatus &aStatus) sl@0: /** sl@0: Updates the single record which matches the unique record ID. sl@0: sl@0: This API ONLY updates the CDecisionRecord result field. The only legal values are ETrue (always) or EFalse (never) sl@0: sl@0: @param aRecordId Specifies the single record to update. sl@0: @param aAllow Allow or reject the request. sl@0: sl@0: @capability AllFiles sl@0: */ sl@0: { sl@0: TIpcArgs args(aRecordId, aAllow); sl@0: CallSessionFunction(EUpdateDecision, args, aStatus); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::CancelUpdateDecision() sl@0: /** sl@0: Cancel an outstanding UpdateDecision request. sl@0: sl@0: Normally this will not be used because an UpdateDecision call will complete very quickly, but sl@0: internally the request is asynchronous and exposing the cancel API allows the cancel code path sl@0: to be tested. sl@0: sl@0: @capability AllFiles sl@0: */ sl@0: { sl@0: CancelSessionFunction(EUpdateDecision); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::DeleteDecisionsForExeL(const TSecureId& aExeSid) sl@0: /** sl@0: Delete all decisions in the database for the specified executable. sl@0: sl@0: @param aExeSid The SID of the executable which has been deleted. sl@0: sl@0: @capability SWI observer plugin SID only sl@0: */ sl@0: { sl@0: User::LeaveIfError(CallSessionFunction(EDeleteDecisionsForExe, TIpcArgs(aExeSid.iId))); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::NotifyPluginsMayHaveChangedL() sl@0: /** sl@0: Notify the UPS that an ECOM plugin has been installed somewhere, which may be an evaluator. sl@0: The UPS will reload all ECOM plugins ASAP. sl@0: sl@0: @capability SWI observer plugin SID only sl@0: */ sl@0: { sl@0: User::LeaveIfError(CallSessionFunction(ENotifyPluginsMayHaveChanged)); sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::NotifyPolicyFilesChanged(TRequestStatus &aStatus) sl@0: /** sl@0: Policy files have been added, changed or deleted. sl@0: sl@0: The UPS server will rebuild its policy file cache and delete decisions which relate to policy files sl@0: which are no longer active (ie. have been deleted, or eclipsed by a policy file with a different sl@0: major version number). sl@0: sl@0: @capability SWI observer plugin SID only sl@0: */ sl@0: { sl@0: TIpcArgs args; sl@0: CallSessionFunction(ENotifyPolicyFilesChanged, args, aStatus); sl@0: sl@0: } sl@0: sl@0: EXPORT_C void RUpsManagement::CancelNotifyPolicyFilesChanged() sl@0: /** sl@0: Cancel a previous call to NotifyPolicyFilesChanged. sl@0: sl@0: Normally this functions should not be used, it is only present for testing the handling sl@0: of abnormal events. sl@0: sl@0: @capability SWI observer plugin SID only sl@0: */ sl@0: { sl@0: CancelSessionFunction(ENotifyPolicyFilesChanged); sl@0: } sl@0: sl@0: sl@0: sl@0: } // End of namespace UserPromptService sl@0: sl@0: // End of file sl@0: