]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/transactions.h
2 * Copyright (c) 2004,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // transactions - generic transaction frame support
28 #ifndef _H_TRANSACTIONS
29 #define _H_TRANSACTIONS
31 #include <security_utilities/utilities.h>
32 #include <security_utilities/debugging.h>
39 // Implementation base class. Do not use directly.
41 class TransactionBase
{
43 // what happens if this object gets destroyed?
45 successful
, // succeeds as set
46 cancelled
, // cancelled (rolled back)
47 conditional
// succeeds normally, cancelled on exception
51 virtual ~TransactionBase();
53 void outcome(Outcome oc
) { mOutcome
= oc
; }
54 Outcome
outcome() const { return mOutcome
; }
57 TransactionBase(Outcome outcome
) : mOutcome(outcome
) { }
59 Outcome
finalOutcome() const;
62 Outcome mOutcome
; // current outcome setting
67 // A ManagedTransaction will call methods begin() and end() on the Carrier object
68 // it belongs to, and manage the "outcome" state and semantics automatically.
69 // You would usually subclass this, though the class is complete in itself if you
70 // need nothing else out of your transaction objects.
72 template <class Carrier
>
73 class ManagedTransaction
: public TransactionBase
{
75 ManagedTransaction(Carrier
&carrier
, Outcome outcome
= conditional
)
76 : TransactionBase(outcome
), mCarrier(carrier
)
83 switch (finalOutcome()) {
97 virtual void commitAction() { mCarrier
.end(); }
98 virtual void cancelAction() { mCarrier
.cancel(); }
104 } // end namespace Security
107 #endif //_H_TRANSACTIONS