//File: CosTransactions.idl
//Part of the Transaction Service

#ifndef _COS_TRANSACTIONS_IDL_
#define _COS_TRANSACTIONS_IDL_

#ifdef _PRE_3_0_COMPILER_
#include <orb.idl>
#pragma prefix "omg.org"
#else
import ::CORBA;
#endif // _PRE_3_0_COMPILER_

module CosTransactions {

#ifndef _PRE_3_0_COMPILER_
typeprefix CosTransactions "omg.org";
#endif // _PRE_3_0_COMPILER_

// DATATYPES 
enum Status {
	StatusActive,
	StatusMarkedRollback,
	StatusPrepared,
	StatusCommitted,
	StatusRolledBack,
	StatusUnknown,
	StatusNoTransaction,
	StatusPreparing,
	StatusCommitting,
	StatusRollingBack
};

enum Vote {
	VoteCommit,
	VoteRollback,
	VoteReadOnly
};

typedef unsigned short TransactionPolicyValue;
// TransactionPolicyValue definitions are deprecated and replaced //
// with new InvocationPolicy and OTSPolicy definitions. They are //
// retained for backward compatibility. //
const TransactionPolicyValue    Allows_shared = 0;
const TransactionPolicyValue    Allows_none = 1;
const TransactionPolicyValue    Requires_shared = 2;
const TransactionPolicyValue    Allows_unshared = 3;
const TransactionPolicyValue    Allows_either = 4;
const TransactionPolicyValue    Requires_unshared = 5;
const TransactionPolicyValue    Requires_either = 6; 

// Forward references for interfaces defined later in module
local interface Current;
interface TransactionFactory;
interface Control;
interface Terminator;
interface Coordinator;
interface RecoveryCoordinator;
interface Resource;
interface Synchronization;
interface SubtransactionAwareResource;

// TransactionalObject has been deprecated.
interface TransactionalObject;

// Structure definitions
struct otid_t {
	long formatID; /*format identifier. 0 is OSI TP */
	long bqual_length;
	sequence <octet> tid;
};

struct TransIdentity {
	Coordinator coord;
	Terminator term;
	otid_t otid;
};
struct PropagationContext {
	unsigned long timeout;
	TransIdentity current;
	sequence <TransIdentity> parents;
	any implementation_specific_data;
};

// Heuristic exceptions
exception HeuristicRollback {};
exception HeuristicCommit {};
exception HeuristicMixed {};
exception HeuristicHazard {};

// Other transaction-specific exceptions
exception SubtransactionsUnavailable {};
exception NotSubtransaction {};
exception Inactive {};
exception NotPrepared {};
exception NoTransaction {};
exception InvalidControl {};
exception Unavailable {};
exception SynchronizationUnavailable {};

// Current transaction 
local interface Current : CORBA::Current {
	void begin()
		raises(SubtransactionsUnavailable);
	void commit(in boolean report_heuristics)
		raises(
			NoTransaction,
			HeuristicMixed,
			HeuristicHazard
		);
	void rollback()
		raises(NoTransaction);
	void rollback_only()
		raises(NoTransaction);
	Status get_status();
	string get_transaction_name();
	void set_timeout(in unsigned long seconds);
	unsigned long get_timeout ();
	Control get_control();
	Control suspend();
	void resume(in Control which)
		raises(InvalidControl);
};

interface TransactionFactory {
	Control create(in unsigned long time_out);
	Control recreate(in PropagationContext ctx);
};

interface Control {
	Terminator get_terminator()
		raises(Unavailable);
	Coordinator get_coordinator()
		raises(Unavailable);
};

interface Terminator {
	void commit(in boolean report_heuristics)
		raises(
			HeuristicMixed,
			HeuristicHazard
		);
	void rollback();
};

interface Coordinator {
	Status get_status();
	Status get_parent_status();
	Status get_top_level_status();

	boolean is_same_transaction(in Coordinator tc);
	boolean is_related_transaction(in Coordinator tc);
	boolean is_ancestor_transaction(in Coordinator tc);
	boolean is_descendant_transaction(in Coordinator tc);
	boolean is_top_level_transaction();

	unsigned long hash_transaction();
	unsigned long hash_top_level_tran();

	RecoveryCoordinator register_resource(in Resource r)
		raises(Inactive);

	void register_synchronization (in Synchronization sync)
		raises(Inactive, SynchronizationUnavailable);

	void register_subtran_aware(in SubtransactionAwareResource r)
		raises(Inactive, NotSubtransaction);

	void rollback_only()
		raises(Inactive);

	string get_transaction_name();

	Control create_subtransaction()
		raises(SubtransactionsUnavailable, Inactive);

	PropagationContext get_txcontext ()
		raises(Unavailable);
};

interface RecoveryCoordinator {
	Status replay_completion(in Resource r)
		raises(NotPrepared);
};

interface Resource {
	Vote prepare()
			raises(
			HeuristicMixed,
			HeuristicHazard
		);
	void rollback()
		raises(
			HeuristicCommit,
			HeuristicMixed,
			HeuristicHazard
		);
	void commit()
		raises(
			NotPrepared,
			HeuristicRollback,
			HeuristicMixed,
			HeuristicHazard
		);
	void commit_one_phase()
		raises(
			HeuristicHazard
		);
	void forget();
};

// TransactionalObject has been deprecated
// and replaced by the OTSPolicy component
// Synchronization will use the OTSPolicy of ADAPTS
// Inheritance from TransactionalObject is for backward compatability/

//PolyORB:WACORBA: TransactionalObject moved before first use of it
// TransactionalObject has been deprecated.
interface TransactionalObject {
};
//PolyORB:WACORBA:

interface Synchronization : TransactionalObject {
	void before_completion();
	void after_completion(in Status s);
};

interface SubtransactionAwareResource : Resource {
	void commit_subtransaction(in Coordinator parent);
	void rollback_subtransaction();
};

//PolyORB:WACORBA:// TransactionalObject has been deprecated.
//PolyORB:WACORBA:interface TransactionalObject {
//PolyORB:WACORBA:};

// TransactionPolicyType is deprecated and replaced
// by InvocationPolicyType and OTSPolicyType
// It is retained for backward compatibility.

//PolyORB:WACORBA: This is duplicate declaration of TransactionPolicyValue
//PolyORB:WACORBA:typedef unsigned short TransactionPolicyValue;

const CORBA::PolicyType    TransactionPolicyType = 46;

interface TransactionPolicy : CORBA::Policy {
	readonly attribute TransactionPolicyValue tpv;
};

typedef unsigned short InvocationPolicyValue;

const InvocationPolicyValue EITHER = 0;
const InvocationPolicyValue SHARED = 1;
const InvocationPolicyValue UNSHARED =2;

typedef unsigned short OTSPolicyValue;

const OTSPolicyValue REQUIRES = 1;
const OTSPolicyValue FORBIDS =2;
const OTSPolicyValue ADAPTS =3;

typedef unsigned short NonTxTargetPolicyValue;

const NonTxTargetPolicyValue PREVENT = 0;
const NonTxTargetPolicyValue PERMIT = 1;

const CORBA::PolicyType INVOCATION_POLICY_TYPE = 55;

interface InvocationPolicy : CORBA::Policy {
	readonly attribute InvocationPolicyValue ipv;
};

const CORBA::PolicyType OTS_POLICY_TYPE = 56;

interface OTSPolicy : CORBA::Policy {
	readonly attribute OTSPolicyValue tpv;
};

// Deprecated
const CORBA::PolicyType NON_TX_TARGET_POLICY_TYPE = 57;

// Deprecated
interface NonTxTargetPolicy : CORBA::Policy {
	readonly attribute NonTxTargetPolicyValue tpv;
};

}; // End of CosTransactions Module

#endif /* ifndef _COS_TRANSACTIONS_IDL_ */
