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

📄 cb200005rs_f.asp.htm

📁 C++builder学习资料C++builder
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<p class=Code><span class=Code>&nbsp;&nbsp;<b> return</b>    

0; </span></p>    

    

<p class=Code><span class=Code>}</span></p>    

    

<p class=Captions><b>Figure    

5:</b> The CORBA    

server after step 1. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> The    

server houses the remote object and infrastructure required for listening to,    

and processing, client messages. The server can be built in a variety of ways,    

including as an NT Service, console application, or multithreaded GUI    

application. In this article, the server is built as a console application.    

Regardless of the implementation, the core steps are the same. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> The    

server is required to house the remote object(s). A server can create several    

remote objects, by first initializing the Object Request Broker, and then    

getting a reference to a Basic Object Adapter (BOA) from the ORB. The server    

then binds one or more implemented objects to the BOA, before telling the BOA    

that it's ready to run. Once the BOA receives a run command, it continues to    

listen and process incoming messages, until it's told to stop or until the    

process stops. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> The BOA    

is responsible for several essential items. The first is registering the object    

with other services required to support the object, including the naming and    

object activation services. The most important thing the BOA handles is how    

client connections and incoming messages are to be handled. Currently, VisiBroker    

handles shared, unshared, and server-per-method (additional support can be    

added to transmit messages encrypted over SSL) policies. In a shared server    

policy, a server can handle multiple clients, with each client being able to    

see the same object. The unshared server starts and ends the remote object for    

each client. Each client will have its own instance of the remote object. In a    

server-per-method policy, a server is started and ended for each method called.    

For more information about the BOA, see the VisiBroker documentation. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Subheads>Building an    

Interface</p>    

    

<p class=BodyText> The    

second step is to build an interface consisting of the methods that can be    

invoked remotely. IDL is used to define the interface of an object system,    

regardless of the target platform or language. By using a neutral interface    

language such as IDL, one can generate the code needed for each target    

platform. This allows an object to communicate with any other object,    

regardless of the platform or language in which it was written. </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> IDL    

allows you to create several elements, including: </p>    

    

<ul>    

<li>Modules:    

modules allow you to group related interfaces.     

    

<li>Interfaces:    

interfaces are a set of attributes and operations that a remote object provides    

to calling objects.     

    

<li>Attributes:    

an attribute is a formal description of a property, with get and set    

operations.     

    

<li>Operations:    

an operation is a method that can be executed by an object. The operation    

includes parameters, returns, and exceptions.     

    

<li>Complex    

types: user-defined data types that can be created including <b>array</b>, <b>sequence</b>,    

<b>struct</b>, <b>enum</b>, <b>union</b>, and <b>typedef</b>. Additionally,    

CORBA 3.0 will allow for passing objects by value.     

    

<li>Exceptions:    

a user-defined exception is passed from the remote object to the client.     

    

    

</ul>    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> <b>Modules.</b> An IDL module allows for grouping    

related interfaces, modules, and other information together. It maps to a class    

that contains the rest of the module. A module statement consists of the    

keyword <b>module</b> followed by a valid identifier. The rest of the module is    

contained between braces. A <b>module</b> statement is optional, and is mainly    

used to aid in grouping related interfaces and definitions. Below is a module    

syntax (bold for keywords and [] for optional parts): </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code> [<b>module</b> <i>identifier</i></span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>};]</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> Here is    

an IDL listing for the example module: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>module</b> NewModule</span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b>interface</b> Class1</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;... </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b>interface</b> Class2</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;... </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>    

    

<p class=Code><span class=Code>}</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> This    

code snippet shows a C++ listing for the example module: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>class</b>    

NewModule</span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b> class</b>    

Class1 : <b>public</b> <b>virtual</b> CORBA_Object</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;... </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b> class</b>    

Class2 : <b>public</b> <b>virtual</b> CORBA_Object</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;... </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;... </span></p>    

    

<p class=Code><span class=Code>}</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> <b>Interfaces.</b> An IDL interface defines the    

interface that client objects see. An IDL interface is composed of operations    

and attributes. The interface may also contain user-defined types and    

exceptions. An interface can inherit the operations and attributes of another    

interface. When the IDL is converted to C++, the class created includes the    

attributes and methods. In addition, it contains additional methods and data    

types. These additional methods are what drive the message passing and allow    

for dynamic discovery and invocation of operations. Below is the syntax for <b>interface</b>:</p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>interface</b> <i>identifier</i> [: <i>interface</i>]</span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;... </span></p>    

    

<p class=Code><span class=Code>};</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> This    

code shows the IDL listing for a customer (available for download; see end of    

article for details): </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>interface</b> customer</span></p>    

    

<p class=Code><span class=Code>{</span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp; <b>attribute</b>    

<b>string</b> name; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b>attribute</b> <b>string</b> address; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b>attribute</b> <b>string</b> city; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b>attribute</b> <b>string</b> state; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b>attribute</b> <b>string</b> zip; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;<b> double</b>    

getBalance();</span></p>    

    

<p class=Code><span class=Code>};</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> <a    

href="#ListingOne">Listing    

One</a> shows the C++ listing for a customer (available for download). </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> <b>Attributes.</b> Attributes are used to define    

properties of an object. An attribute consists of a type and name. In C++ it    

maps to get and set methods of the same name as the attribute. An attribute can    

also be read-only and generate only the get method. To make an attribute    

read-only, use the keyword <b>readonly</b> before the <b>attribute</b> keyword.    

Here is the syntax of <b>attribute</b>:</p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code> [<b>readonly</b>]    

<b>attribute</b> <i>type</i> <i>identifier</i>;</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> Below is    

an example of attributes in IDL: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>attribute</b> <b>string</b> name; </span></p>    

    

<p class=Code><span class=Code><b>readonly</b> <b>attribute</b> <b>double</b>    

balance; </span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> And here    

is an example of attributes mapped to C++:</p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><b>public</b>    

<b>void</b> name(string name); </span></p>    

    

<p class=Code><span class=Code><b>public</b>    

string name();</span></p>    

    

<p class=Code><span class=Code><b>public</b>    

<b>double</b> balance();</span></p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=BodyText> <b>Operations.</b> Operations are methods that a    

client object can execute. An operation consists of parameters, a return, and    

exceptions. Parameters consist of a mode, type, and parameter name. The mode    

specifies the direction in which a value is passed. The mode can be <b>in</b>    

from the calling object, <b>out</b> to the calling object, or both directions    

using <b>inout</b>. An operation is defined just as a method in C++: the return    

type followed by the operation name. Next is the list of parameters and any    

defined exceptions the class may throw. Below is the syntax of an operation: </p>    

    

<p class=BodyText> &nbsp; </p>    

    

<p class=Code><span class=Code><i>type</i> <i>identifier</i>([<i>type</i> <i>param</i>,    

...]) [<b>raises</b> (<i>exception</i>)];</span></p>    

⌨️ 快捷键说明

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