#include <stdio.h>
#include "checkpoint.h"

int
normalAction1 (HC_Sequence_t *seq, void *userdata)
{
  seq = seq;
  userdata = userdata;

  printf( "1\n" );

  return (HC_NormalSuccess( seq, 2 ));
}

int
normalAction2 (HC_Sequence_t *seq, void *userdata)
{
  seq = seq;
  userdata = userdata;

  printf( "2\n" );

  return (HC_NormalSuccess( seq, 3 ));
}

int
normalAction3 (HC_Sequence_t *seq, void *userdata)
{
  static int count = 0;
  seq = seq;
  userdata = userdata;

  count++;
  printf( "3\n" );

  if( count == 1 )
    return (HC_NormalFail( seq, 0 ));

  return (HC_NormalSuccess( seq, 4 ));
}

int rollbackAction3 (HC_Sequence_t *seq, void *userdata,
		     unsigned long checkpoint)
{  
  printf( "rollback3\n" );
  return (HC_RollBackSuccess (seq, 0));
}

int
normalAction4 (HC_Sequence_t *seq, void *userdata)
{
  seq = seq;
  userdata = userdata;

  printf( "4\n" );

  exit(0);
}


int main (int argc, char *argv[])
{
  HC_NodelistNode_t nodes[] = {
    {1, HC_NORMALFUNC, normalAction1},
    {2, HC_NORMALFUNC, normalAction2},
    {3, HC_NORMALFUNC, normalAction3},
    {4, HC_NORMALFUNC, normalAction4},
    {3, HC_ROLLBACKFUNC, rollbackAction3},
    {0, HC_LISTEND, NULL}
  };

  HC_Sequence_t *seq;
  int rc;

  printf("This should print: \n1\n2\n3\nrollback3\n3\n4\n\n");
  
  seq = HC_NewSequence (nodes);

  // This should never return
  rc = HC_CallSequence (seq, NULL, 1);

  printf ("HC_CallSequence returned: %s\n", HC_Strerror (rc));

  return(0);
}
