-- Copyright (C) 2009 John Millikin <jmillikin@gmail.com>-- -- This program is free software: you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation, either version 3 of the License, or-- any later version.-- -- This program is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.-- -- You should have received a copy of the GNU General Public License-- along with this program. If not, see <http://www.gnu.org/licenses/>.-- moduleGnome.Keyring.Internal.Operation(-- * Public APIOperation,async,async',sync-- * Implementation helpers for within G.KR,OperationImpl,operationImpl,voidOperation,maybeTextOperation,textListOperation)whereimportControl.Exception(throwIO)importControl.Monad(join)importData.Text.Lazy(Text)importGnome.Keyring.Internal.FFIimportGnome.Keyring.Internal.TypesdataOperationa=Operation{async::(Error->IO())->(a->IO())->IOCancellationKey,syncImpl::IO(Result,a)}-- Synchronous operation public APIsync::Operationa->IOasyncop=do(res,x)<-syncImplopcaseresofRESULT_OK->returnx_->throwIO$resultToErrorres-- Helper for async operations which return nothing usefulasync'::Operationa->(Error->IO())->IO()->IOCancellationKeyasync'oponErroronSuccess=asyncoponError(constonSuccess)-- Implementation details of async operationstypeOperationImplab=(FunPtra->Ptr()->DestroyNotifyPtr->IOCancellationKey)->IO(Result,b)->OperationboperationImpl::((CInt->IOa->IO())->IO(FunPtrb))->OperationImplbaoperationImplimplasyncIO=Operation$\onErroronSuccess->docallback<-impl$\cresio->caseresultcresofRESULT_OK->io>>=onSuccessx->onError$resultToErrorxdestroy<-wrapDestroyNotify$\ptr->doletstable=castPtrToStablePtrptrjoin$deRefStablePtrstablefreeStablePtrstablestable<-newStablePtr$dofreeHaskellFunPtrcallbackfreeHaskellFunPtrdestroyasyncIOcallback(castStablePtrToPtrstable)destroy-- Available basic operation typesvoidOperation::OperationImplDoneCallback()voidOperation=operationImpl$\checkResult->wrapDoneCallback$\cres_->checkResultcres$return()maybeTextOperation::OperationImplGetStringCallback(MaybeText)maybeTextOperation=operationImpl$\checkResult->wrapGetStringCallback$\crescstr_->checkResultcres$peekNullableTextcstrtextListOperation::OperationImplGetListCallback[Text]textListOperation=operationImpl$\checkResult->wrapGetListCallback$\creslist_->checkResultcres$mapGListpeekTextlist