**********
a1.c
**********
/*--------------------------------------------------------------------------

  File: a1.c

  Send a simple message from Module A -> Module B

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "examples.h"

main()
{ 
  SAMPLE_1_TYPE sample;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  sample.x = 17;
  sample.str = (char *)malloc(sizeof(char)*4);
  sample.str[0] = 'a';
  sample.str[1] = 'b';
  sample.str[2] = 'c';
  sample.str[3] = '\0';
  
  tcaAddConstraint("sampleMsg", &sample);
}


**********
a2.c
**********
/*--------------------------------------------------------------------------

  File: a2.c

  Primitive Examples

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "prim.h"

main()
{ 
  INT_TYPE x;
  FLOAT_TYPE f;
  DOUBLE_TYPE d;
  CHAR_TYPE c;
  STRING_TYPE str;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  x = 17;
  f = 1.0;
  d = 2.0;
  c = 'A';
  str = (STRING_TYPE)malloc(sizeof(char)*4);
  str[0] = 'a';
  str[1] = 'b';
  str[2] = 'c';
  str[3] = '\0';
  
  tcaExecuteCommand("intMsg", &x);
  tcaExecuteCommand("floatMsg", &f);
  tcaExecuteCommand("doubleMsg", &d);
  tcaExecuteCommand("charMsg", &c);
  tcaExecuteCommand("stringMsg", &str);
}


**********
a3.c
**********
/*--------------------------------------------------------------------------

  File: a3.c

  Struct examples

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "structs.h"

main()
{ 
  STRUCT_1_TYPE struct1;
  STRUCT_2_TYPE struct2;
  STRUCT_3_TYPE struct3;
  STRUCT_4_TYPE struct4;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  struct1.x = 1;
  struct1.y = 2;
  struct1.z = 3;

  struct2.x = 1;
  struct2.c = 'A';
  struct2.f = 2.0;

  struct3.x = 1;
  struct3.c = 'A';
  struct3.f = 2.0;

  struct4.x = 1;
  struct4.c = 'A';
  struct4.f = 2.0;

  tcaExecuteCommand("struct1Msg", &struct1);
  tcaExecuteCommand("struct2Msg", &struct2);
  tcaExecuteCommand("struct3Msg", &struct3);
  tcaExecuteCommand("struct4Msg", &struct4);
}


**********
a4.c
**********
/*--------------------------------------------------------------------------

  File: a4.c

  Array Examples

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "arrays.h"

main()
{
  int i, j, accessor;
  FIXED_ARRAY_TYPE fixArray;
  VARIABLE_ARRAY_TYPE varArray;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  printf("Fixed Array\n");

  for(i=0; i<FIXED_ARRAY_DIM1; i++) {
    for(j=0; j<FIXED_ARRAY_DIM2; j++) {
      fixArray[i][j] = i+j;
      printf("%d ", fixArray[i][j]);
    }
    printf("\n");
  }

  printf("Variable Array\n");

  varArray.dim1 = VAR_ARRAY_DIM1;
  varArray.dim2 = VAR_ARRAY_DIM2;
  varArray.elements = (char **)malloc(sizeof(char *) * 
				     varArray.dim1 * varArray.dim2);
  for(i=0; i < varArray.dim1; i++){
    for(j=0; j < varArray.dim2; j++) {
      /* Can't do multiple subscripts on variable length arrays */
      accessor = i + j*varArray.dim1;
      varArray.elements[accessor] = (char *)malloc(sizeof(char)*10);
      sprintf(varArray.elements[accessor], "%d-%d\0", i, j);
      printf("%s ", varArray.elements[accessor]);
    }
    printf("\n");
  }

  tcaExecuteCommand("fixedArrayMsg", fixArray); /* &fixArray is ignored */
  tcaExecuteCommand("varArrayMsg", &varArray);
}


**********
a5.c
**********
/*--------------------------------------------------------------------------

  File: a5.c

  Link Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "link.h"

main()
{
  LINK_PTR link;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  link = (LINK_TYPE *)malloc(sizeof(LINK_TYPE));
  link->a = 1;
  link->b = 2;
  link->s = (char *)malloc(sizeof(char)*4);
  link->s[0] = 'a';
  link->s[1] = 'b';
  link->s[2] = 'c';
  link->s[3] = '\0';
  link->next = (LINK_TYPE *)malloc(sizeof(LINK_TYPE));
  link->next->a = 3;
  link->next->b = 4;
  link->next->s = (char *)malloc(sizeof(char)*4);
  link->next->s[0] = 'e';
  link->next->s[1] = 'f';
  link->next->s[2] = 'g';
  link->next->s[3] = '\0';
  link->next->next = NULL;

  tcaExecuteCommand("linkMsg", link);
}


**********
a6.c
**********
/*--------------------------------------------------------------------------

  File: a6.c

  Register Name Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "name.h"

main()
{
  TWO_POINTS_TYPE twoPoint;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  twoPoint.p1.x = 1.0;
  twoPoint.p1.y = 2.0;
  twoPoint.p1.z = 3.0;

  twoPoint.p2.x = 4.0;
  twoPoint.p2.y = 5.0;
  twoPoint.p2.z = 6.0;

  tcaExecuteCommand("twoPointMsg", &twoPoint);
}


**********
a7.c
**********
/*--------------------------------------------------------------------------

  File: a7.c

  Query Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "query.h"

main()
{ 
  SAMPLE_TYPE sample, reply;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  sample.x = 17;
  sample.str = (char *)malloc(sizeof(char)*4);
  sample.str[0] = 'a';
  sample.str[1] = 'b';
  sample.str[2] = 'c';
  sample.str[3] = '\0';
  
  tcaQuery("queryMsg", &sample, &reply);

  printf("reply.x  : %d\n", reply.x);
  printf("reply.str: %s\n", reply.str);
}



**********
a8.c
**********
/*--------------------------------------------------------------------------

  File: a8.c

  Non blocking query example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "query.h"

main()
{ 
  SAMPLE_TYPE sample, reply;
  TCA_REF_PTR queryRef1, queryRef2;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  sample.x = 17;
  sample.str = (char *)malloc(sizeof(char)*4);
  sample.str[0] = 'a';
  sample.str[1] = 'b';
  sample.str[2] = 'c';
  sample.str[3] = '\0';
  
  tcaQuerySend("queryMsg", &sample, &queryRef1);
  tcaQuerySend("queryMsg", &sample, &queryRef2);

  tcaQueryReceive(queryRef2, &reply);

  printf("query 2\n");
  printf("reply.x  : %d\n", reply.x);
  printf("reply.str: %s\n", reply.str);

  tcaQueryReceive(queryRef1, &reply);

  printf("query 1\n");
  printf("reply.x  : %d\n", reply.x);
  printf("reply.str: %s\n", reply.str);
}



**********
a9.c
**********
/*--------------------------------------------------------------------------

  File: a9.c

  Non blocking query example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "blockingCom.h"

main()
{ 
  SAMPLE_TYPE sample;
  TCA_RETURN_VALUE_TYPE status;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  sample.x = 17;
  sample.str = (char *)malloc(sizeof(char)*4);
  sample.str[0] = 'a';
  sample.str[1] = 'b';
  sample.str[2] = 'c';
  sample.str[3] = '\0';
  
  status = tcaWaitForCommand("successMsg", &sample);

  if (status == Success) {
    printf("Success\n");
  } else {
    printf("Failure\n");
  }

  status = tcaWaitForCommand("failureMsg", &sample);

  if (status == Success) {
    printf("Success\n");
  } else {
    printf("Failure\n");
  }
}



**********
aa.c
**********
/*--------------------------------------------------------------------------

  File: aa.c

  Handler Example

--------------------------------------------------------------------------*/

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

main()
{ 
  int x, i;
  char *str;

  printf("Connect ...\n");
  tcaConnectModule("Module A", tcaServerMachine());

  tcaWaitUntilReady();

  x = 17;
  str = (char *)malloc(sizeof(char)*4);
  str[0] = 'a';
  str[1] = 'b';
  str[2] = 'c';
  str[3] = '\0';
  
  tcaExecuteCommand("stringMsg", &str);

  tcaExecuteCommand("intMsg", &x);

  tcaQuery("stringQueryMsg", &str, &i);

  printf("i: %d\n", i);
}



**********
arrays.h
**********
/*--------------------------------------------------------------------------

  File: arrays.h

  Arrays include file

--------------------------------------------------------------------------*/

#define FIXED_ARRAY_DIM1 2
#define FIXED_ARRAY_DIM2 3

typedef int FIXED_ARRAY_TYPE[FIXED_ARRAY_DIM1][FIXED_ARRAY_DIM2];

#define FIXED_ARRAY_FORMAT "[int : 2, 3]"

#define VAR_ARRAY_DIM1 3
#define VAR_ARRAY_DIM2 2

/* variable length (2D) array of strings */
typedef struct { 
  int dim1;
  int dim2;
  char **elements; 
} VARIABLE_ARRAY_TYPE;

#define VARIABLE_ARRAY_FORMAT "{int, int, <string : 1, 2>}"


**********
b1.c
**********
/*--------------------------------------------------------------------------

  File: b1.c

  Send a simple message from Module A -> Module B

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "examples.h"

void sampleMsgHnd(ref, sample)
TCA_REF_PTR ref;
SAMPLE_1_PTR sample;
{
  printf("sample->x  : %d\n", sample->x);
  printf("sample->str: %s\n", sample->str);

  tcaFreeData(tcaReferenceName(ref), sample);
}

main()
{
  printf("Connect ...\n");
  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("sampleMsg", ConstraintClass, "{int, string}", NULL);
  tcaRegisterHandler("sampleMsg", "sampleMsgHnd", sampleMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}  

**********
b2.c
**********
/*--------------------------------------------------------------------------

  File: b2.c

  Primitive Examples

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "prim.h"

void intMsgHnd(ref, x)
TCA_REF_PTR ref;
INT_PTR x;
{
  printf("*x : %d\n", *x);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), x);
}


void floatMsgHnd(ref, f)
TCA_REF_PTR ref;
FLOAT_PTR f;
{
  printf("*f : %f\n", *f);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), f);
}

void doubleMsgHnd(ref, d)
TCA_REF_PTR ref;
DOUBLE_PTR d;
{
  printf("*d : %f\n", *d);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), d);
}

void charMsgHnd(ref, c)
TCA_REF_PTR ref;
CHAR_PTR c;
{
  printf("*c : %c\n", *c);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), c);
}

void stringMsgHnd(ref, str)
TCA_REF_PTR ref;
STRING_PTR str;
{
  printf("*str: %s\n", *str);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), str);
}

main()
{
  printf("Connect ...\n");

  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("intMsg", CommandClass, INT_FORMAT, NULL);
  tcaRegisterHandler("intMsg", "intMsgHnd", intMsgHnd);

  tcaRegisterMessage("floatMsg", CommandClass, FLOAT_FORMAT, NULL);
  tcaRegisterHandler("floatMsg", "floatMsgHnd", floatMsgHnd);

  tcaRegisterMessage("doubleMsg", CommandClass, DOUBLE_FORMAT, NULL);
  tcaRegisterHandler("doubleMsg", "doubleMsgHnd", doubleMsgHnd);

  tcaRegisterMessage("charMsg", CommandClass, CHAR_FORMAT, NULL);
  tcaRegisterHandler("charMsg", "charMsgHnd", charMsgHnd);

  tcaRegisterMessage("stringMsg", CommandClass, STRING_FORMAT, NULL);
  tcaRegisterHandler("stringMsg", "stringMsgHnd", stringMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}

**********
b3.c
**********
/*--------------------------------------------------------------------------

  File: b3.c

  Structs example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "structs.h"

void struct1MsgHnd(ref, s)
TCA_REF_PTR ref;
STRUCT_1_PTR s;
{
  printf("struct 1\n");
  printf("s->x: %d\n", s->x);
  printf("s->y: %d\n", s->y);
  printf("s->z: %d\n", s->z);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), s);
}

void struct2MsgHnd(ref, s)
TCA_REF_PTR ref;
STRUCT_2_PTR s;
{
  printf("struct 2\n");
  printf("s->x: %d\n", s->x);
  printf("s->f: %f\n", s->f);
  printf("s->c: %c\n", s->c);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), s);
}

void struct3MsgHnd(ref, s)
TCA_REF_PTR ref;
STRUCT_3_PTR s;
{
  printf("struct 3\n");
  printf("s->x: %d\n", s->x);
  printf("s->f: %f\n", s->f);
  printf("s->c: %c\n", s->c);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), s);
}

void struct4MsgHnd(ref, s)
TCA_REF_PTR ref;
STRUCT_4_PTR s;
{
  printf("struct 4\n");
  printf("s->x: %d\n", s->x);
  printf("s->f: %f\n", s->f);
  printf("s->c: %c\n", s->c);
  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), s);
}

main()
{
  printf("Connect ...\n");

  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("struct1Msg", CommandClass, STRUCT_1_FORMAT, NULL);
  tcaRegisterHandler("struct1Msg", "struct1MsgHnd", struct1MsgHnd);

  tcaRegisterMessage("struct2Msg", CommandClass, STRUCT_2_FORMAT, NULL);
  tcaRegisterHandler("struct2Msg", "struct2MsgHnd", struct2MsgHnd);

  tcaRegisterMessage("struct3Msg", CommandClass, STRUCT_3_FORMAT, NULL);
  tcaRegisterHandler("struct3Msg", "struct3MsgHnd", struct3MsgHnd);

  tcaRegisterMessage("struct4Msg", CommandClass, STRUCT_4_FORMAT, NULL);
  tcaRegisterHandler("struct4Msg", "struct4MsgHnd", struct4MsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}

**********
b4.c
**********
/*--------------------------------------------------------------------------

  File: b4.c

  Arrays Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "arrays.h"

void fixedArrayMsgHnd(ref, fixedArray)
TCA_REF_PTR ref;
FIXED_ARRAY_TYPE fixedArray;
{ 
  int i, j;

  printf("fixedArrayMsgHnd: start.\n");

  for(i=0; i < FIXED_ARRAY_DIM1; i++) {
    for(j=0; j < FIXED_ARRAY_DIM2; j++)
      printf("%d ", fixedArray[i][j]);
    printf("\n");
  }

  printf("fixedArrayMsgHnd: done.\n");

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), fixedArray);
}

void varArrayMsgHnd(ref, varArray)
TCA_REF_PTR ref;
VARIABLE_ARRAY_TYPE *varArray;
{ 
  int i, j, accessor;

  printf("varArrayMsgHnd: start.\n");

  for(i=0; i < varArray->dim1; i++){
    for(j=0; j < varArray->dim2; j++) {
      /* Can't do multiple subscripts on variable length arrays */
      accessor = i + j*varArray->dim1;
      printf("%s ", varArray->elements[accessor]);
    }
    printf("\n");
  }

  printf("varArrayMsgHnd: done.\n");

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), varArray);
}

main()
{
  printf("Connect ...\n");

  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("fixedArrayMsg", CommandClass, FIXED_ARRAY_FORMAT, NULL);
  tcaRegisterHandler("fixedArrayMsg", "fixedArrayMsgHnd", fixedArrayMsgHnd);

  tcaRegisterMessage("varArrayMsg", CommandClass, VARIABLE_ARRAY_FORMAT, NULL);
  tcaRegisterHandler("varArrayMsg", "varArrayMsgHnd", varArrayMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}

**********
b5.c
**********
/*--------------------------------------------------------------------------

  File: b5.c

  Link Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "link.h"

void linkMsgHnd(ref, link)
TCA_REF_PTR ref;
LINK_PTR link;
{
  LINK_PTR tmp;

  printf("linkMsgHnd: start.\n");

  tmp = link;
  while (tmp) {
    printf("link->a: %d\n", tmp->a);
    printf("link->b: %d\n", tmp->b);
    printf("link->s: %s\n", tmp->s);
    printf("\n");
    /* should free this list when we are done with it. */
    tmp = tmp->next;
  }

  printf("linkHnd: done.\n");

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), link);
}

main()
{
  printf("Connect ...\n");

  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("linkMsg", CommandClass, LINK_FORMAT, NULL);
  tcaRegisterHandler("linkMsg", "linkMsgHnd", linkMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}

**********
b6.c
**********
/*--------------------------------------------------------------------------

  File: b6.c

  Register Name Format Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "name.h"

void twoPointMsgHnd(ref, twoPoint)
TCA_REF_PTR ref;
TWO_POINTS_PTR twoPoint;
{
  printf("twoPointMsgHnd: start.\n");

  printf("twoPoint->p1.x: %f\n", twoPoint->p1.x);
  printf("twoPoint->p1.y: %f\n", twoPoint->p1.y);
  printf("twoPoint->p1.z: %f\n", twoPoint->p1.z);

  printf("twoPoint->p2.x: %f\n", twoPoint->p2.x);
  printf("twoPoint->p2.y: %f\n", twoPoint->p2.y);
  printf("twoPoint->p2.z: %f\n", twoPoint->p2.z);

  printf("twoPointMsgHnd: done.\n");

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), twoPoint);
}

main()
{
  printf("Connect ...\n");

  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterNamedFormatter(NEW_NAME_FORMAT, POINT_FORMAT);

  tcaRegisterMessage("twoPointMsg", CommandClass, TWO_POINTS_FORMAT, NULL);
  tcaRegisterHandler("twoPointMsg", "twoPointMsgHnd", twoPointMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}

**********
b7.c
**********
/*--------------------------------------------------------------------------

  File: b7.c

  Query Example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "query.h"

void queryMsgHnd(ref, sample)
TCA_REF_PTR ref;
SAMPLE_PTR sample;
{
  SAMPLE_TYPE reply;

  printf("sample->x  : %d\n", sample->x);
  printf("sample->str: %s\n", sample->str);

  reply.x = 42;
  reply.str = sample->str;

  tcaReply(ref, &reply);
  tcaFreeData(tcaReferenceName(ref), sample);
}

main()
{
  printf("Connect ...\n");
  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("queryMsg", QueryClass, "{int, string}", 
		     "{int, string}");

  tcaRegisterHandler("queryMsg", "queryMsgHnd", queryMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}  

**********
b8.c
**********
/*--------------------------------------------------------------------------

  File: b8.c

  Non-blocking query example

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "query.h"

int count;

void queryMsgHnd(ref, sample)
TCA_REF_PTR ref;
SAMPLE_PTR sample;
{
  SAMPLE_TYPE reply;

  printf("sample->x  : %d\n", sample->x);
  printf("sample->str: %s\n", sample->str);

  reply.x = count++;
  reply.str = sample->str;

  tcaReply(ref, &reply);
  tcaFreeData(tcaReferenceName(ref), sample);
}

main()
{
  count = 0;
  printf("Connect ...\n");
  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterMessage("queryMsg", QueryClass, "{int, string}", 
		     "{int, string}");

  tcaRegisterHandler("queryMsg", "queryMsgHnd", queryMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}  

**********
b9.c
**********
/*--------------------------------------------------------------------------

  File: b9.c

  Blocking command example.

--------------------------------------------------------------------------*/

#include <stdio.h>
#include "tca.h"
#include "blockingCom.h"

void successMsgHnd(ref, sample)
TCA_REF_PTR ref;
SAMPLE_PTR sample;
{
  printf("sample->x  : %d\n", sample->x);
  printf("sample->str: %s\n", sample->str);

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), sample);
}

void failureMsgHnd(ref, sample)
TCA_REF_PTR ref;
SAMPLE_PTR sample;
{
  printf("sample->x  : %d\n", sample->x);
  printf("sample->str: %s\n", sample->str);

  tcaFailure(ref, "example fail", NULL);
  tcaFreeData(tcaReferenceName(ref), sample);
}

main()
{
  printf("Connect ...\n");
  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterCommandMessage("successMsg", "{int, string}");
  tcaRegisterHandler("successMsg", "successMsgHnd", successMsgHnd);

  tcaRegisterCommandMessage("failureMsg", "{int, string}");
  tcaRegisterHandler("failureMsg", "failureMsgHnd", failureMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}  


**********
ba.c
**********
/*--------------------------------------------------------------------------

  File: ba.c

  Handler Example

--------------------------------------------------------------------------*/

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

void stringMsgHnd(ref, s)
TCA_REF_PTR ref;
char **s;
{
  printf("s: %s\n", *s);

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), s);
}

void intMsgHnd(ref, x)
TCA_REF_PTR ref;
int *x;
{
  printf("x: %d\n", *x);

  tcaSuccess(ref);
  tcaFreeData(tcaReferenceName(ref), x);
}


void stringQueryMsgHnd(ref, s)
TCA_REF_PTR ref;
char **s;
{
  int x;

  printf("s: %s\n", *s);

  tcaFreeData(tcaReferenceName(ref), s);

  x = 17;

  tcaReply(ref, &x);
}


main()
{
  printf("Connect ...\n");
  tcaConnectModule("Module B", tcaServerMachine());

  tcaRegisterCommandMessage("stringMsg", "string");
  tcaRegisterHandler("stringMsg", "stringMsgHnd", stringMsgHnd);

  tcaRegisterCommandMessage("intMsg", "int");
  tcaRegisterHandler("intMsg", "intMsgHnd", intMsgHnd);

  tcaRegisterQueryMessage("stringQueryMsg", "string", "int");
  tcaRegisterHandler("stringQueryMsg", "stringQueryMsgHnd", stringQueryMsgHnd);

  tcaWaitUntilReady();

  tcaModuleListen();
}  

**********
blockingCom.h
**********
/*--------------------------------------------------------------------------

  File: blockingCom.h

  Blocking Command Include File

--------------------------------------------------------------------------*/

typedef struct {
  int x;
  char *str;
} SAMPLE_TYPE, *SAMPLE_PTR;



**********
examples.h
**********
/*--------------------------------------------------------------------------

  File: examples.h

  Structures and message information for examples.

--------------------------------------------------------------------------*/

typedef struct {
  int x;
  char *str;
} SAMPLE_1_TYPE, *SAMPLE_1_PTR;



**********
link.h
**********
/*--------------------------------------------------------------------------

  File: link.h

  Link include file

--------------------------------------------------------------------------*/

typedef struct _LINK_TYPE {
  int a;
  int b;
  struct _LINK_TYPE *next;
  char *s;
} LINK_TYPE, *LINK_PTR;

#define LINK_FORMAT "{int, int, *!, string}"

**********
makefile
**********
#
# Makefile for TCA tutorials
#

# Point this to the location of the tca top-level directory
TCADIR = /usr/mars/mars/sixLegRelease/tca

LIBTCA =  $(TCADIR)/lib
TCAPATH = $(TCADIR)/include

CFLAGS = -g  -I$(TCAPATH)

OBJS = \
    a1.o \
    b1.o 

all: a1 b1 a2 b2 a3 b3 a4 b4 a5 b5 a6 b6 a7 b7 a8 b8 a9 b9 aa ba

a1: a1.o
	cc $(CFLAGS) -o a1 a1.o  -L$(LIBTCA) -ltca_sun4

b1: b1.o
	cc $(CFLAGS) -o b1 b1.o -L $(LIBTCA) -ltca_sun4


a2: a2.o
	cc $(CFLAGS) -o a2 a2.o  -L$(LIBTCA) -ltca_sun4

b2: b2.o
	cc $(CFLAGS) -o b2 b2.o -L $(LIBTCA) -ltca_sun4


a3: a3.o
	cc $(CFLAGS) -o a3 a3.o  -L$(LIBTCA) -ltca_sun4

b3: b3.o
	cc $(CFLAGS) -o b3 b3.o -L $(LIBTCA) -ltca_sun4


a4: a4.o
	cc $(CFLAGS) -o a4 a4.o  -L$(LIBTCA) -ltca_sun4

b4: b4.o
	cc $(CFLAGS) -o b4 b4.o -L $(LIBTCA) -ltca_sun4


a5: a5.o
	cc $(CFLAGS) -o a5 a5.o  -L$(LIBTCA) -ltca_sun4

b5: b5.o
	cc $(CFLAGS) -o b5 b5.o -L $(LIBTCA) -ltca_sun4


a6: a6.o
	cc $(CFLAGS) -o a6 a6.o  -L$(LIBTCA) -ltca_sun4

b6: b6.o
	cc $(CFLAGS) -o b6 b6.o -L $(LIBTCA) -ltca_sun4


a7: a7.o
	cc $(CFLAGS) -o a7 a7.o  -L$(LIBTCA) -ltca_sun4

b7: b7.o
	cc $(CFLAGS) -o b7 b7.o -L $(LIBTCA) -ltca_sun4


a8: a8.o
	cc $(CFLAGS) -o a8 a8.o  -L$(LIBTCA) -ltca_sun4

b8: b8.o
	cc $(CFLAGS) -o b8 b8.o -L $(LIBTCA) -ltca_sun4


a9: a9.o
	cc $(CFLAGS) -o a9 a9.o  -L$(LIBTCA) -ltca_sun4

b9: b9.o
	cc $(CFLAGS) -o b9 b9.o -L $(LIBTCA) -ltca_sun4


aa: aa.o
	cc $(CFLAGS) -o aa aa.o  -L$(LIBTCA) -ltca_sun4

ba: ba.o
	cc $(CFLAGS) -o ba ba.o -L $(LIBTCA) -ltca_sun4

clean:
	rm *.o a1 b1 a2 b2 a3 b3 a4 b4 a5 b5 a6 b6 a7 b7 a8 b8 a9 b9 aa ba




**********
name.h
**********
/*--------------------------------------------------------------------------

  File: name.h

  Name include file

--------------------------------------------------------------------------*/

typedef struct {
  float x, y, z;
} POINT_TYPE, *POINT_PTR;

#define POINT_FORMAT "{float, float, float}"

#define NEW_NAME_FORMAT "point"

typedef struct {
  POINT_TYPE p1, p2;
} TWO_POINTS_TYPE, *TWO_POINTS_PTR;

#define TWO_POINTS_FORMAT "{point, point}"

**********
prim.h
**********
/*--------------------------------------------------------------------------

  File: prim.h

  Fill in message format for primitive types

--------------------------------------------------------------------------*/

typedef int INT_TYPE, *INT_PTR;
#define INT_FORMAT "int"

typedef float FLOAT_TYPE, *FLOAT_PTR;
#define FLOAT_FORMAT "float"

typedef double DOUBLE_TYPE, *DOUBLE_PTR;
#define DOUBLE_FORMAT "double"

typedef char CHAR_TYPE, *CHAR_PTR;
#define CHAR_FORMAT "char"

typedef char *STRING_TYPE, **STRING_PTR;
#define STRING_FORMAT "string"





**********
query.h
**********
/*--------------------------------------------------------------------------

  File: query.h

  Query Include File

--------------------------------------------------------------------------*/

typedef struct {
  int x;
  char *str;
} SAMPLE_TYPE, *SAMPLE_PTR;



**********
structs.h
**********
/*--------------------------------------------------------------------------

  File: structs.h

  Fill in message format for structs

--------------------------------------------------------------------------*/

typedef struct {
  int x;
  int y;
  int z;
} STRUCT_1_TYPE, *STRUCT_1_PTR;

#define STRUCT_1_FORMAT "{int, int, int}"

/*************************************************/

typedef struct {
  int x;
  char c;
  float f;
} STRUCT_2_TYPE, *STRUCT_2_PTR;

#define STRUCT_2_FORMAT "{int, char, float}"

/*************************************************/

typedef struct {
  char c;
  int x;
  float f;
} STRUCT_3_TYPE, *STRUCT_3_PTR;

#define STRUCT_3_FORMAT "{char, int, float}"

/*************************************************/

typedef struct {
  float f;
  int x;
  char c;
} STRUCT_4_TYPE, *STRUCT_4_PTR;

#define STRUCT_4_FORMAT "{int, float, char}"

/*************************************************/

