Chinaunix首页 | 论坛 | 博客
  • 博客访问: 170288
  • 博文数量: 77
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 990
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-21 18:13
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(76)

我的朋友

分类:

2009-07-08 21:00:20

l       STRING

l       VIEW

定义

伪代码中VIEW的使用

代码示例

l       FML

定义

伪代码中FML的使用

代码示例

l       结合FMLVIEW

l       CARRAY的定义

l       FML32VIEW32


STRING

TUXEDO使用固定类型的数据缓冲进行远程或本地进程间通讯。例如”STRING”就是一种包含了字符数组的一种数据缓冲。绝大多数商业应用需要不止一种数据。

TUXEDO已经预定义了一些数据缓冲类型用以传递各种数据。每种都有其独特的处理方法和相应特性。

STRING

STRING类型缓冲是一串以NULL结尾的字符。TUXEDOSTRING类型编、解码。无论缓冲分配了多大,将由NULL所在位置决定其长度。

TUXEDOSTRING缓冲的使用与C语言程序中的字符数组非常类似。

分配

buf = tpalloc ( “STRING”, NULL, 4*1024);

用法

strcpy ( buf “HELLO WORLD”);

调用交易

tpcall (“INQUIRY”, buf , 0, &buf, &len, 0);

 

 

 


 

VIEW的概念和例子

TUXEDO使用VIEW类型数据缓冲处理结构或复杂数据类型。

使用VIEW的优点:

²       结构化数据表示,可以方便地访问数据元素

²       将多个数据元素绑定在一个定义良好的数据结构上

缺点:

²       所有数据元素都通过,不检查合法性

范例:

struct MYVIEW {
  float   float1;
  double  double1;
  long    long1;
  short   short1;
  int     int1;
  dec_t   dec1;
  char    char1;
  char    string1[20];
  unsigned short L_carray1[2];    /* length array of carray1 */
  short   C_carray1;              /* count of carray1 */
  char    carray1[2][20];
};

$ /* View data structure */
  VIEW MYVIEW
  #type   cname   fbname  count   flag    size    null
  float   float1  -       1       -       -       -
  double  double1 -       1       -       -       -
  long    long1   -       1       -       -       -
  short   short1  -       1       -       -       -
  int     int1    -       1       -       -       -
  dec_t   dec1    -       1       -       9,16    -
  char    char1   -       1       -       -       -
  string  string1 -       1       -       20      -
  carray  carray1 -       2       CL      20      -
  END

  

使用VIEW的步骤:

²       建立一个VIEW文件

²       设置环境变量

VIEWDIR=$APPDIR

VIEWFILES= cust.V,other.V

export VIEWDIR VIEWFILES

²       编译VIEW文件

viewc –n cust.V

²       在代码中包含头文件

²       编译

²       运行

代码范例:

#include

#include “atmi.h”

#include “cust.h”

main(int argc, char *argv [ ])

{

       struct cust *buf;

       long rcvlen;

       if (tpinit ((TPINIT *) NULL) == -1)

{

              ptintf(“tpinit(): %s\n”,tpstrerror (tperrno));

              exit(1);

}

       buf=(struct cust *)tpalloc(“VIEW”,”cust”,sizeof(struct cust));

       if (buf == (struct cust *)NULL)

{

              printf(“ERROR:tpalloc(VIEW,cust),%s\n”,tpstrerror(tperrno));

              tpterm();

              exit(1);

}

       strcpy(buf->fsst_name,”Mel”);

       strcpy(buf->lst_name,”Gibson”);

       buf->acct_id = 10002;

       buf->branch_id = 5;

       ret = tpcall (“INQUIRY”,(char *)buf,0,

                                   (char **)&buf,&rcvlen,0);

       if( ret == -1)

{

              printf( “tpcall(INQUIRY): %s\n”, tpstrerror(tperrno));

              tpfree((char *) buf);

              tpterm();

              exit(1);

}

              printf( “Returned amount is : %1.1s\n”, buf->amount);

              tpfree((char *)buf);

              tpterm();

}


 

 

 

概念

 

       预定义方式的VIEW有一些缺点:

²       改变不灵活

²       结构变化时,所有程序需要重新编译

²       即使没有数据,空间也被占用

为克服以上缺点,TUXEDO提供另一种预定义数据,按照‘名字/值’组对格式组织数据。该方式称为FMLFielded Manipulation Language)。

FML由以下部分构成:

²       FML API

²       FML命令行工具

 

FML头部,包含索引

FLOAT1

500

DOUBLE1

1234

LONG1

12345

SHORT1

12

域名

域值

 

 

使用FML的步骤

²       建立一个FML文件:bank.flds

# name       number    type     flags   comments
  FLOAT1     110       float    -       -
  DOUBLE1    111       double   -       -
  LONG1      112       long     -       -
  SHORT1     113       short    -       -
  INT1       114       long     -       -
  DEC1       115       string   -       -
  CHAR1      116       char     -       -
  STRING1    117       string   -       -
  CARRAY1    118       carray   -       -

 

 

²       设置环境变量

FLDTBLDIR=$APPDIR:$TUXDIR/udataobj

FIELDTBLS=bank.flds,Usysflds

export FLDTBLDIR FIELDTBLS

²       mkfldhdr编译

mkfldhdr bank.flds

²       编码

参见下一章节

²       编译程序

buldclient –f atmclt.c –o atmclt

FML API

#include

Falloc(int num_of_flds,FLDLEN space)

Finit(FBFR *f)

Fsizeof(FBFR *f,FLDLEN len)

Fadd(FBFR *f,FLDID fldid,int oc,char *value,FLDLEN len)

Fprint(FBFR *f)

Fget(FBFR *f,FLDID fldid,int oc,char *value,FLDLEN len)

Fchg(FBFR *f,FLDID fldid,int oc,char *value,FLDLEN len)

Fcpy(FBFR *f, FBFR *f2)

f = (FBFR *)tpalloc(“FML”,NULL,200)

Ffprint(FBFR *fbfr,FILE *iop)

²       Fprint()是一个有用的调试函数,因为它可以打印出缓冲内容而不需要定义数据类型和输出格式。

²       Falloc()用于内部进程通讯

²       Fcpy()用来复制FML的内容,特别是在不同服务的交易之间

代码范例:

#include

#include “atmi.h”

#include

#include “bank.flds.h”

int main (int argc,char **argv)

{

       long account ;

       float balance;

       float amount;

       FBFR *sendBuf, *recvBuf;

       sendBuf = (FBFR *) tpalloc(RMLTYPE,NULL,Fneeded(20,4*1024));

       recvBuf = (FBFR *) tpalloc(RMLTYPE,NULL,Fneeded(20,4*1024));

       if (Fchg(sendBuf, ACCOUNT_ID,0,(char * )&account,0) == -1)

{

              printf(“\nERROE:Fchg(ACCOUNT_ID):%s\n”,Fstrerror(Ferror));

}

       if(tpcall(“INQUIRY”,(char *)sendBuf,0,

(char **)&recvBuf,&len,TPSIGRSTRT)== -1

{

       if(Fget(recvBuf,STATLIN,0,tmpstr,0)!= -1)

{

              printf(“\n%s\n”,tmpstr);

}

              printf(“\nERROR: tpcall(INQUIRY):%s\n”,tpstrerror(tperrno));

       else

{

       if(Fget(recvBuf,BALANCE,0,(char *)&balance,0) == -1)

{

              printf(“\nERROR:Fget(BALANCE):%s\n”,Fstrerror(Ferror));

}

       else

{

              printf(“\nBalance:%s\n”,balance);

}

}

              tpfree((char *) sendbuf);

              tpfree((char *) recvbuf);

       tpterm();

}


 

FMLVIEW

       FML的使用需要进一步的考虑,例如,访问FML数据会慢一些,因为接口要插入或取回数据。在某些场合,需要进行一些推敲。而VIEW则提供了一个通用管理数据缓冲的方案。

       FML的优点是可以在机器间传递数据和灵活的存储数据。而VIEW则传递整个定义好的C结构,不管域里面是否有数据。可以使用它们的混合:FML-VIEWS

       TUXEDO提供了2APIFML转换成VIEW

²       int Fvstof(FBRF *bufptr,char *cstruct,int mode,char *view)VIEW结构转成FML

²       int Fvftos(FBFR *bufptr, char *cstruct, char *view)       FML数据转成VIEW结构


 

       FMLVIEWSTRING类型外,另外一个主要的数据缓冲类型是CARRY

CARRY

CARRY数据缓冲类型是一种定长的,相对独立于机器的数据。

²       长度需要定义

²       不进行编/解码

²       可用来传递二进制数据

²       可以作为FMLVIEW的子项

²       用于文件、图形传输

FML32VIEW32

       在对FMLVIEWS初始化时,寻址是16位的。随着主要的平台都变成32位的,TEXUDO增加了FML32VIEWS32

²       使用32位寻址方式

²       有更大的寻址空间(2GB

²       API16位的相似,只在名字上加了‘32字样

阅读(1549) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~