⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 -

📁 一个多线程
💻
📖 第 1 页 / 共 2 页
字号:
它是一个多线程,多流程的脚本编译解释平台,能够同时运行多份类似于下面的脚本代码:(流程可以直接加载任意接口的动态库,执行数据库库访问,存储过程和sql语句),加载支持双借口的com.)
     它是一个通讯平台,不同应用程序(不论是否在同一台机器)均可使用消息机制进行同步或异步调用,不同程序的脚本之间也可以用这种机制进行沟通,各模块之间只需知道对方的模块id和对象id即可,bus总线允许多个节点间进行消息接力,应用层不必关心。
    所有的脚本,所有的应用程序模块和对象均可以跑在总线上。
    总线类CDataBus,总线通讯对象CAsynWorker,总线流程对象CAWFlow
 
下面是总线控制脚本,你的应用程序可以加载你自己的脚本和扩展自己的脚本函数
脚本函数的定义在后面


busmg.txt
////////////////////////////////////////////////////////////
//the bus set up flow
//write by hongjiaming
//this flow is designed for bus manager in unival.dll ,the manager is global object,cant be deleted,so you cant use the releaseflow instrument to exit the flow
////////////////////////////////////////////////////////////
style 'busdrv.cmd'
defproc InitProc
defproc CloseProc 
defproc SendToBus
defproc ProcessCommand dword dwCommandID, dword ApplyObject,dword CommandType
variant bexit, timeCount
////////////////////////////////////////////////////////////
//main loop function
//write by hongjiaming
////////////////////////////////////////////////////////////
startmain
 bexit=FALSE
 AuthorName='Jiaming.Hong.'
 variant dwCommandID,ApplyObject,CommandType,infomation
 while TRUE then 
  GetCommand dwCommandID ApplyObject CommandType
  ProcessCommand dwCommandID ApplyObject CommandType
  if(bexit)then break
 endwhile
endmain
///////////////////////////////////////////////////////////////////
//the dll status changed,if 
//if get in,you should send the shukehands data to each other
//write by hjm
///////////////////////////////////////////////////////////////////
startproc DealCommStatus
 variant typeid,dwConnectHandle,actid,istatus,bserver
 GetAllCommandParam typeid,dwConnectHandle,actid,istatus,bserver
 variant Data,ilen
 switch istatus then
 case 0
  /////////////////////////////////////////////
  //get in
  //report his modid and name to the other side
  /////////////////////////////////////////////
  datalen StationName ilen
  ilen=ilen+1
  setblock Data ilen+8
  blockopr Data,1,3,0,LEN -4
  blockopr Data,StationModId,3,4,LEN -4
  blockopr Data,StationName,3,8,LEN 0-ilen
  WriteRemoteData 0xffffffff,Data,ilen+8,TYPE 0,CONNECT dwConnectHandle
 break
 default
  //////////////////////////////////////////////////
  //disconnected
  //////////////////////////////////////////////////
  CheckBusLink
 break
 endswitch
endproc
//////////////////////////////////////////////////////////////////////////////
//report my modid
//write by hjm
/////////////////////////////////////////////////////////////////////////////
startproc SetLinkReport
variant connect,modid,ilen,Data
 GetAllCommandParam connect,modid
 datalen StationName ilen
 ilen=ilen+1
 setblock Data ilen+8
 blockopr Data,1,3,0,LEN -4
 blockopr Data,StationModId,3,4,LEN -4
 blockopr Data,StationName,3,8,LEN 0-ilen
 WriteRemoteData 0xffffffff,Data,ilen+8,TYPE 0,CONNECT connect
endproc
//////////////////////////////////////////////////////////////////////////////
//deal with data which from tcp/ip or other port
//the packet data is classified according :
//system data,type=0
//data received,type=1,but passed by,to other module
//data received,type=1,but for this module 
//type=other,reserved for :such as transfer file,data,ot other data,and interface to other type bus
///////////////////////////////////////////////////////////////////////////////
startproc DealCommData
 variant typeid,dwConnectHandle,bufferid
 GetAllCommandParam typeid,dwConnectHandle,bufferid
 variant modid,remotedata,len,type,iszap,iscode
 //dword bufferid,int & modid,datablock 0 & remotedata,int & len,int & type,int & iszap,int & iscode
 while 1 then
  GetPDUData bufferid,modid,remotedata,len,type,iszap,iscode
  variant ilen
  if(len)then
   datalen remotedata ilen
   //,TYPE int type=1,CONNECT int hconnect=0,ZAP int iszap=0,CODE int iscode=0
   switch type then
   case 0//system data
    variant codeid
    blockopr remotedata,codeid,3,0,LEN 4
    switch codeid then
    case 1//report modid and name
     variant oldmodid,Cmodid,modname
     modname=''
     blockopr remotedata,Cmodid,3,4,LEN 4
     blockopr remotedata,modname,3,8,LEN ilen-8
     oldmodid=Cmodid
     ChangModName dwConnectHandle,Cmodid,modname
     if oldmodid!=Cmodid then
      setblock remotedata 8
      blockopr remotedata,2,3,0,LEN -4
      blockopr remotedata,Cmodid,3,4,LEN -4
      WriteRemoteData Cmodid,remotedata,0,TYPE 0,CONNECT dwConnectHandle
     else
      setblock remotedata 4
      blockopr remotedata,4,3,0,LEN -4
      WriteRemoteData Cmodid,remotedata,0,TYPE 0,CONNECT dwConnectHandle
     endif
    break
    case 2//remote side (server) change my modid
     blockopr remotedata,StationModId,3,4,LEN 4
     ChangModName 0,StationModId,StationName
     SetReportOver dwConnectHandle
    break
    case 4//response for report
     SetReportOver dwConnectHandle
    break
    case 3//remote side change its modname
     modname=''
     blockopr remotedata,modid,3,4,LEN 4
     blockopr remotedata,modname,3,8,LEN ilen-8
     ChangModName dwConnectHandle,modid,modname
    break
    case 10//report online/offline
     WriteRemoteData modid,remotedata,len,TYPE type,CONNECT dwConnectHandle,ZAP iszap,CODE iscode
    break
    case 12//notify the remote need report
     WriteRemoteData modid,remotedata,len,TYPE type,CONNECT dwConnectHandle,ZAP iszap,CODE iscode
    break
    endswitch
   break
   case 1//bus packet data
    if modid==StationModId then
     //////////////////////////////////////////////////////////////////////
     //if iszap then
     //iszap=0
     //uncompress the data
     //endif
     //
     //if iscode then
     //iscode=0
     //uncode the data
     //endif
     //////////////////////////////////////////////////////////////////////
    endif
    WriteRemoteData modid,remotedata,len,TYPE type,ZAP iszap,CODE iscode
   break
   default
   //other data
   break
   endswitch
  else
   break
  endif
 endwhile
endproc
////////////////////////////////////////////////////////////////////////
//data from bus for send
//call WriteRemoteData to send it to remote module
//write by hjm
///////////////////////////////////////////////////////////////////////
startproc SendRemoteData
 variant modid,remotedata,len,times
 GetAllCommandParam modid,remotedata,len,times
 variant iszap,iscode
 ///////////////////////////////////////////////////////////////////////
 // data is  coded ,compressed here
 //the len is chenged,the flag iszap,iscode changed
 ///////////////////////////////////////////////////////////////////////
 WriteRemoteData modid,remotedata,len,ZAP iszap,CODE iscode TIM times
endproc
/////////////////////////////////////////////////////////////////////////////
//call this proc for notify the online message for applyor
//write by hjm
///////////////////////////////////////////////////////////////////////////////
startproc SetOnLineReport
 variant apply,object,flag
 GetAllCommandParam apply,object,flag
 variant remotedata
 switch(flag)then
 case 0//online
 case 1//offline
  setblock remotedata 12
  blockopr remotedata,10,3,0,LEN -4
  blockopr remotedata,object,3,4,LEN -4
  blockopr remotedata,flag,3,8,LEN -4
  WriteRemoteData apply,remotedata,12,TYPE 0
 break
 case 2//notify
  setblock remotedata 8
  blockopr remotedata,12,3,0,LEN -4
  blockopr remotedata,apply,3,4,LEN -4
  WriteRemoteData object,remotedata,8,TYPE 0
 break
 default
 break
 endswitch
endproc
////////////////////////////////////////////////////////////
//event process procedure
//write by hongjiaming
////////////////////////////////////////////////////////////
startproc ProcessCommand dword dwCommandID, dword ApplyObject,dword CommandType
 switch dwCommandID then
 case ID_CMD_INIT//init
  InitProc
 break
 case ID_CMD_CLOSE//close
  CloseProc
 break
 case ID_SendToBus//bus message
  SendToBus
 break
 case ID_DealCommStatus//comm dll status changed
  DealCommStatus
 break
 case ID_DealCommData//comm dll data arrived
  DealCommData
 break
 case ID_SendRemoteData//data for send
  SendRemoteData
 break
 case ID_SetLinkReport//need report
  SetLinkReport
 break
 case ID_SetOnLineReport//need OnLine report
  SetOnLineReport
 break
 case ID_CMD_TIME//time
  if (timeCount==0&&bexit==0)then
   CheckBusLink
   timeCount=timeCount+1
  else
   timeCount=timeCount+1
   if(timeCount>=3)then timeCount=0
  endif
 endswitch
endproc
//////////////////////////////////////////////////////////////////////////
//init the proc here
//write by hjm
///////////////////////////////////////////////////////////////////////////
startproc InitProc
 timeCount=0
 InitEdau 0,THREADNUM 0
 CheckBusLink
 timeCount=timeCount+1
 AddTimeOutMessage 5, 111,CFLAG 1
endproc
 
///////////////////////////////////////////////////////////////////////
//do something before exit
//write by hjm
///////////////////////////////////////////////////////////////////////
startproc CloseProc
 CancelTimeOutMessage 111
 bexit=TRUE
endproc
/////////////////////////////////////////////////////////////////////////
//no use now for bus
//write by hjm
//////////////////////////////////////////////////////////////////////////
startproc SendToBus

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -