#ifndef _TRANSMANH
#define _TRANSMANH

#include "declarations.h"

//semaphore
#include "semaphore.h"

//threads
#include "threads.h"

typedef struct{
  bool local;           // replica where the transaction is executed
  bool executedByAll;   // the sentence sql is executed by all replicas
  bool localNode;       // replica is local node to driver jdbc
  bool finished;        // only for local transactions
  bool committable;     // the transaction has been to-delivered
  bool executing;       // only for local transactions
  bool aborting;        // the transaction has been submitted for abortion
  bool committing;      // the transaction has been submitted for commitment
  bool commitreceived;  // for remote transactions
  
  long writeset_length; // length of writeset field
  T_writeset writeset;  // the commit msg can arrive before the to-msg
  
  hot_uint32 qmId;       // QM assigned
  hot_uint32 mclientId;
  
  hot_uint32 idConnection; // connection id
  hot_uint32 idPetition;   // petition id
  int recordsUpdates;      // number of records updated, inserted, deleted...
  int error; // 100703 dcadena. 0 not error, 1 error
  
  Conns_M conns;
  long response_length; // length of response
  char response[TAMBUFFERJDBC];  // response
  
  T_Trans transaction;
} T_Transaction;

void PrintAborts();

// 280803
//void Start(int,int,int);
void Start(int);
void ChangeReplicaID(int);

void Opt_Delivery (Opt_M);

void To_Delivery(To_M);

// 250703
void Init_Delivery (Opt_M);

void Commit(Commit_M);

void View_Change(T_Mess*);

void Send_Reply(T_Mess*);

void Query (Opt_M);

// 250603
//void postExecute(T_Tid, char[], long, hot_uint32);
//void postAbort(T_Tid, hot_uint32);
//void postCommit(T_Tid, hot_uint32);
int postExecute(T_Tid, char[], long, char[], long, int);
void postAbort(T_Tid);
void postCommit(T_Tid, hot_uint32);

#endif

