ѧ
JOURNAL OF SOFTWARE
2000Vol.11No.3P.393-397



ֲʽAdaϵͳʵ
ű
ժҪAda 95οֲḽ¼Eֲʽϵͳе˼,ʵֲַʽAdaϵͳһЩ˼,ʵַͨϵͳľ巽.ڴ˻,ͨһЩǰô,ʵֵķͨϵͳĽӿ,ʵ˷ֲʽAdaϵͳ.ͨһʵ,˷ֲʽAdaϵͳĳƷ.
ؼʡ,Զ̵̹,ͨϵͳ,Stub,,.
ͼšTP312
Implementation for Distributed Ada Language System
ZHANG BingLI Gan-shengWANG Hua-min
(Department of Computer Science and Engineering Zhejiang University Hangzhou310027)
AbstractAccording to Ada 95 reference manual(E),some concepts and design ideas implemented in distributed Ada Language system are introduced in the paper,and the detailed implementation of the partition communication subsystem is given.With the interfaces of partition communication subsystem and some pre-processings,the remote procedure calls in distributed Ada language system are implemented.Finally,an example is given.
Key wordsPartition,remote procedure call,partition communication subsystem,Stub,marshelling,unmarshelling.
AdaԼӦ֧ŻܹڿӦĿ,Щ̴漰Ƕʽϵͳ.,漰ɢϷʽķֲʽȺϵͳĹĿ,رǱͨͨӵǶʽӦ˵,еAdaԻṩЧ֧.ֲʽAdaϵͳ־Ⱥϵͳ,ʹһAdaֲȺϵͳϲִ.
ڹ,GNU֯ColoradoѧϵԷֲʽAdaп,Ƕ޷Ada 95淶ʹӦÿԱ漰.һЩѧоڷֲʽ,CC++Ĺ϶,ڷֲʽAda滹ûͬĹ.
ĽķֲʽAdaϵͳѭAda 95 οֲḽ¼Eֲʽϵͳı׼,˴ǰô,ӦÿԱ˵,ֲʽӦϵͳʱԿݡ,ÿ֮ͨϸ.ͬʱ,ӦÿԱٵؽӴײͨʩ,ӶֲʽӦϵͳİȫ.
1ֲʽAdaϵͳ˼
AdaƵĴ͹.1983,γɹʱ׼Ada 83.˺,Ϊ˽뷽ںAda,һAda 83Ĺ,γµı׼Ada 95.Ada 95οֲḽ¼E˷ֲʽAdaϵͳ˼1ݣһAda򻮷ֳɸ,ÿӦڷֲʽϵͳһڵ,ֹͨЭϵͳĹ.
ֲʽAdaķǿⵥԪļ.
ڷֲʽAdaϵͳ,Զ̵̹ãremote procedure call,RPCǲȱٵҪ,ͨԶ̵̹,ֲʽAdaϵͳилؽ,ͬϵͳ.
Ada 95οֲḽ¼E˷ͨϵͳpartition communication subsystemһֽӿ,Զ̵̹þͨӿṩĸֺɵ.
1.1ֲʽAdaϵͳԶ̵̹û
ڷֲʽAdaϵͳԶ̵̹õĻͼ1ʾ.

Fig.1Basic RPC frame for distributed Ada language system
ͼ1ֲʽAdaϵͳRPC
ʵRPCĹ,Stub,ͻͷ񷽶ͨԵStubԶ̵̹,νStubǷͨŵһγ.ڷֲʽAdaϵͳ,StubһζԷͨϵͳнӿڵõĳ.
1.2ֲʽAdaϵͳ͸
Andrews S.Tanenbaumڷֲʽϵͳ͸Ե52ݣλ͸ԡǨ͸ԡ͸ԡ͸ԺͲ͸.
Ada 95¼E,ûж͸Խϸ.,͸ǷֲʽϵͳĹؼ֮һ.ڷֲʽAdaϵͳӦ,÷ֲʽAdaϵͳֲʽӦóʱӦ㡢,ϲ漰̣,5͸÷ֲʽAdaϵͳķֲʽӦϵͳжʵ,ûڶԶ̹̽еõʱ,ؿǵ÷λ,˽ĵùڵĽڵ,֪ʵĶǷӿɿԵĸ,ͬʱûɹԴ,ϵͳжǨҲܸĸ.磺
AdaԶ̵̹ʽΪ
package A is һ
pragma Remoter-Call-Interface(A);
procedure P(......);
......
end A;

with A;һ
package B is 
......
A.P(......);һԶ̵̹
......
end B.
ͨĳԿ,Զ̵̹õʽ뱾صãݽṹһµ.˶ڷع̵ûԶ̵̹,ϵͳӦԶʶ,Ҫϵͳλ͸.ڵײĴʵ,TCP/IPЭ,ˣڷֲʽAdaϵͳķ,ӦIPַӦ,ͽ˷ֲʽϵͳǨ͸.͸,ͨ.
2ͨϵͳʵ
ͨϵͳPCSΪһֲʽķ֮ĳṩ˽ͨŵһӿ.
2.1ͽ̵ʵ
Դͽ,PCSṩ
procedure write(stream:in out string; item:in implementation-defined);
procedure read(stream:in out string; item:out implementation-defined; last:out integer).
writeṩĹ,вstreamΪĲ,ΪԶ̵̹òitemַַ͡͡͡͡ö͡¼͵֮һ.ƹAdaṩػ,writereadеĲItemͶ.ûʱ,writeؿҪдеǺ,readؿǴжһ͵ת.
ڷͨϵͳ,Ϊַʽ,ʽŵ㣺(1) ַĲַ֮໥תʵ,ϵͳҲṩһֺ.(2) 紫ݲĵײ,LinuxµSUN RPCʵһЩCԵRPCĺ,Щǽַ͵Ļϵ,AdaCַ֮û໥ת.
ڶԿͻ,涨һΪϢ֮ķָǰ˱ضַ,ʶͬ첽,ҪõĹ.ڶԷ񷽵ķ,涨ǰ˼ضַ,Ƿɹ.
2.2̵ʵ
LinuxµSUN RPC,ԽлCԵRPC.һRPCʵ,Ҫǣڷ񷽺ͿͻҪǼ˫ԼԶ̵̹ĳš汾ź͹̺,ṩԼͣⲿݱʾ׼XDRв.ṩĺҲвȫĵط,޷ж,ӵݽṹʱӦÿԱҪĹXDRԱдӵݽṹ,Ҫ,ͬʱҲܷ.ˣLinuxµSUN RPC޷ɷֲʽAdaϵͳҪ.
Ϊ,ʵһַRPCc-stub,̹˴̵,ַͬԶ̴ݺ첽ַԶ̴,ǰ߷һַȴһַ,߷һַ.
PCSڿͻṩ¹̣
procedure do-rpc(partition:in partition-id; params:in string; result:out string);
procedure do-apc(partition:in partition-id; params:in string).
do-rpcṩͬԶ̵̹õĹ.3ֱΪš.do-apcṩ첽Զ̵̹õĹ.ֱΪź.
ָṩԶ̷Ľڵ.÷,do-rpcѷšز󴫵ݸc-stub,c-stubŹ涨ķ񷽷.c-stubյز,ٽ˲ظdo-rpc.
PCSڷṩ˹̣
procedure Establish-RPC-Receiver.
Establish-RPC-ReceiverǸ޲Ĺ,Ҫǳʼ,պͷͲ.,ֻڷǰôɵһAda,ɷ񷽵stub.
3ǰôйع
ڿͻ,ǰôĿΪʹӦÿԱʹñϵͳʱؿ̵ϸ.
ǰôĹǶԱpragma(Remote-Call-Interface)ĳ˵д,һֵͬĳ.ûƱصõԶ̵ʱ,˴˰ֵͬĹ,˹ͨPCSеĽӿ˴͡աstub.
,ĳԶ̳˵£
package testfunc is
pragma Remote-Call-Interface(testfunc); ʾtestfuncһԶ̳
function testfunc1(i:in integer; j:in integer) return integer;
...
end testfunc.
˵ǰôԶɵĳ£
with ada-rpc;use ada-rpc;
package body testfunc is
function testfunc1(i:in integer;j:in integer) return integer is 
inparams,result:string(1..implementation-defined);ɸûҪ峤
resultparams:integer;صĲ
last:integer;ָʾǰеλ
begin
write(inparams,testfunc1);&&
write(inparams,i);&&
write(inparams,j);&&
do-rpc(partition-id-1,inparams,result);&&ڳʼж
last:=1;
read(result,resultparams,last);&&
return(resultparams);
end testfunc1;
...
end testfunc.
Կ,ûڵԶ̹testfunc.testfunc1ʱȴ˱´testfuncеĺtestfunc1,testfunc1ͨPCSĽӿ˿ͻstub.
ڷ,ǰôҲԱpragma(remote-call-interface)ĳ˵˴,һAdaada-call-func,ɴϢع̵õĹ.˹Ada-rpc.Establish-RPC-Receiver,յͻĲ,Ȩada-call-func,Ѳݸada-call-func,ada-call-func̶Բн,ݽĲִع,ӦشĲEstablish-RPC-Receiver,Establish-RPC-Receiverشͻ.,˷񷽵Stub.潫ͨһֲʽĽ,Ada-rpcһЩصǰôһֲʽAdaӦϵͳ.
4һֲʽ⣺ģݿ
ȡף3,ĶĴ䲻ͬ.
ݵпģʽ:Ҫݷʱ,յ¥㼰ҪķϢ.ÿݷѯź,յÿݷصĵǰ¥㼰ϡ»ֹ.ĸЩϢ,ĳ㷨,ʺϵĵڿҪ¥з.
ݷֲʽAda˼,һݿƳ򻮷Ϊ3ͼ2ʾķݷͿ˷,дصķֲʽAda.

Fig.2Partitions ofr simulating lift control
ͼ2ģݿƵķ
3ֱֲ3̨΢,ɵĹǣ˷ķ¥ҪϻҪµ,ĽӵݷѯϢ,ÿݵ¥ؿķ,ķϿ˵,ָʾʵĵݵڵ¥,˷Ϊĵݵ.
Ϊ񷽵ĵݷṩҪʡ˳ľʵ֣У
filename:liftcontrol.ads&&ݷṩԶ̳Ĺ˵
package liftcontrol is
pragma Remote-Call-Interface;
procedure quest-lift(liftnum:in integer;direction:out integer;layer:out in teger)
&&ܿĵĲѯ,صݵ˶¥
function control-lift(liftnum:in integer; layer:in integer) return integer
&&ܿĵָ,ָĵǰָ¥,ֵʾָǷЧ
end liftcontrol.
ΪǷǿͻĿķṩҪУ
filename:controlfunc.ads&&ǿṩԶ̳Ĺ˵
package controlfunc is
pragma Remote-Call-Interface;
function requestfunc(layer:in integer;upordown:in integer) return integer;
&&ܿͻ,Եݷвѯ,ͨһѵ㷨ĳݽз,
&&Ȼ󷢳ָ,󷵻ظͻҪзĵݺ.
end controlfunc.
ӦÿԱӦдĳΪͻĿ˷ĳΪ,ԣ.ڷֲʽAdaϵͳеǰùԤPP,ͬʱPPӦÿԱдϵͳɷ.УPPֱcontrolfunc.adsliftcontrol.adsļд,ÿһstubܵĳ,ÿṩķһ,ͻ.Щǰôɵĳûдĳ򾭱ɿִļ,ٷֲԵĽڵϼ.
ӿ,ӦÿԱƵķֲʽͨĳ򼸺û,ؿԶ̵̹λúͷõľϸ.ڵײʵֵĴʵǻLinuxµSUN RPCɵ,SUN RPCֲ֧Ͳе͸,ñϵͳӦϵͳҲֲ֧Ͳе͸,,ڶ˷,֮佫,Բ.ڸ͸,ӦÿԱǷҪӸ.
5
AdaǴ.ͬʱ,Ƕʽϵͳеõ㷺Ӧ.,ǶʽϵͳǷֲʽϵͳ,ӦϵͳĳûзֲʽAdaд,Ϊʵֲַ,ӦÿԱͲòԼдʵԶ̵̹úͲͬڵϵĳ֮ͨ.ЩӦÿԱǿ,Щϸϱ뻨Ѵʱ.ʹñϵͳṩĹ֮,ֲʽĳƾͨĳûʲô,Ժ̺ԶͨõĴϸ.ǱĿҪĿ.
ű,1974,˶ʿ,ҪоΪ,,д .,1940,ڣʿʦ,ҪоΪ,, Զ.,Ů1944,ڣҪоΪʵ ,.
ͨѶϵ: 310027,㽭ѧѧ빤ϵ
ߵλű(㽭ѧѧ빤ϵݡ310027)
(㽭ѧѧ빤ϵݡ310027)
(㽭ѧѧ빤ϵݡ310027)
ο
1ISO/IEC 9652:1995(E).Ada reference manuallanguage and standard libraries.1995
2Tanenbaum A S.Distributed operating system.Englewood Cliffs,NJ:Prentice Hall,Inc.,1995
3Wellings A J.Issues in distributed processing-session summary.In:Proceedings of the 1st International Workshop on RealTime Ada Issues.ACM Ada Letters,1987,7(6):5760
1998-10-06յԭ,1999-04-12յ޸ĸ
