如何编写CORBA VMS的方法

CORBA VMS how to write the method?

本文关键字:方法 VMS CORBA 何编写      更新时间:2023-10-16

我正在学习用CORBA编写一个数字媒体管理程序。我不知道如何实现方法VMSgetMediaAvailable()引发(ServerException)。

VMS.idl:

module VMS {
 enum Genre { g_undefined, SciFi, Comedy, Action, Horror, Docu };
 enum StatusType { s_undefined, available, lent };
struct VMSMedia {
long   ObjectId;
long   ProviderId;
Genre  Type;
string Title;
string ProductionCountry;
short  ProductionYear;
short  Length;
StatusType Status;
};
struct VMSProvider {
long   ObjectId;
string Name;
string FirstName;
long   ZIPCode;  /* short does not work */
string Address;
};
exception ServerException {
string reason;
};
typedef sequence<VMSMedia>    VMSMediaSeq;
typedef sequence<VMSProvider> VMSProviderSeq;
interface VMSRepository {
readonly attribute long currentMaxProviderId;
readonly attribute long currentMaxMediaId;    
oneway void save ();
oneway void addProvider (in VMSProvider p);
oneway void delProvider (in long id);    
VMSProvider getProvider (in long id) 
  raises (ServerException);
VMSProviderSeq getProviders () 
  raises (ServerException);
oneway void addMedia (in VMSMedia p);
oneway void delMedia (in long id);    

VMSMedia getMedia (in long id) 
  raises (ServerException);
VMSMediaSeq getMediaOfType (in Genre type) 
  raises (ServerException);
VMSMediaSeq getMediaYoungerThan (in short year) 
  raises (ServerException);
 //here new Method
 VMSMediaSeq getMediaAvailable () raises
 (ServerException);
  };
 };

我所拥有的就是在类Repository_i.cc:

 void
 VMSRepository_i::VMSMediaSeq getMediaAvailable () {
  }

我知道我必须在那个IDL文件中创建一个新的Stub和一个新的Skelton,我必须实现这个方法。我需要问是否有可用的媒体,所以我必须做一个if- Statement对吗?但是我不知道我该怎么做。

getMediaAvailable()的实现将需要填充
的序列struct VMSMedia。您必须使用OS/库调用来查找可用的序列并填充序列。

搜索一下如何在CORBA中填充序列,这并不难。