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

📄 cb200005rs_f.asp.htm

📁 C++builder学习资料C++builder
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  <td width=247 valign=top style='width:185.0pt;border-top:none;border-left:    

  none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;    

  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;    

  padding:0in 5.4pt 0in 5.4pt'>    

  <p class=BodyText> Standard    

  for watching the usage of an object. </p>    

  </td>    

 </tr>    

</table>    

    

<p class=Captions><b>Figure    

1:</b> CORBA services. </p>    

    

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

    

<p class=BodyText> A CORBA    

facility provides a framework and standards for building applications. By    

specifying standards for applications, companies can build applications that    

interact with outside agencies. Computer departments and software vendors can    

produce standard applications that can be mixed and matched. </p>    

    

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

    

<p class=BodyText> CORBA    

has several benefits over traditional two, three, and <i>n</i>-tier    

client/server systems: </p>    

    

<ul>    

<li>The    

programmer uses a familiar method for using the remote object.     

    

<li>Users    

can find, query, and invoke methods of the remote object dynamically.     

    

<li>Using    

interfaces one can invoke a method without knowledge of the actual behavior.     

    

<li>CORBA    

objects can be written in a variety of languages, including C++, COBOL, Java,    

Ada, Smalltalk, and Object Pascal.     

    

<li>Integration    

of legacy systems can be accomplished by hiding them behind an interface.     

    

<li>CORBA    

allows objects to seamlessly interact with each other regardless of the    

location, language, or platform.     

    

<li>CORBA    

can scale from a stand-alone palmtop to the enterprise.     

    

    

</ul>    

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

    

<p class=Subheads>How Does    

CORBA Work? </p>    

    

<p class=BodyText> The    

first stop in understanding how CORBA works is messages. The heart of object    

interactivity is the message. A message is composed of four pieces: the target    

object, method name, parameters for the method, and a return value. Parameters    

and a return value are optional. In C++, a message looks like this: </p>    

    

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

    

<p class=Code><span class=Code>vendor1.setCompanyName(&quot;Apres    

Technology Group, Inc.&quot;); </span></p>    

    

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

    

<p class=BodyText> Essentially    

the message tells <i>vendor1</i> to execute    

its <i>setCompanyName</i> method passing in    

the parameter of "Apres Technology Group, Inc." If the <i>vendor1</i> object has a <i>setCompanyName</i>    

method that accepts a string as a parameter, it will respond to the message. To    

have an object communicate with <i>vendor1</i>    

remotely, you just have to have a mechanism for sending the message to another    

process, either on the same or a remote computer. </p>    

    

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

    

<p class=BodyText> It would    

be nice if the message passing were hidden from the programmer, making the    

remote object call transparent. In investigating how objects work with    

messages, you'll find that objects are composed of two parts: the interface and    

the implementation. See the sidebar "<a href="#SidebarOne">C++Builder    

References</a>" for information on objects. An interface is a set of    

messages to which an object will respond. It's similar to the definition of an    

object, except that it's composed only of the messages or methods that the    

underlying object will accept. This allows an object to call another object and    

execute a method of that object without knowing the underlying implementation.    

This ability to send messages to an object regardless of the implementation is    

what allows for polymorphism. </p>    

    

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

    

<p class=BodyText> C++    

allows for the defining of an interface using an abstract class. An object can    

inherit from one or more abstract classes. In addition, an object can be    

referenced by its abstract superclass. For example, suppose a <i    

style='mso-bidi-font-style:normal'>HouseContract</i> object is derived from a <i    

style='mso-bidi-font-style:normal'>Contract</i> abstract class. Then anyone who    

references a <i>Contract</i> class object could interact with the object,    

completely ignoring other methods the object may implement. A new type of    

contract can be easily created and integrated into the application by simply    

deriving a new contract object. </p>    

    

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

    

<p class=BodyText> So what    

do interfaces have to do with CORBA? CORBA uses the separation of interface and    

implementation to build a framework of underlying objects to pass the actual    

message. The programmer first specifies an interface, then defines the    

implementation of the methods defined by the interface. The complexity of    

passing messages is hidden from the programmer by inheriting from a basic    

object that encapsulates the communication with the object. Using this approach,    

the programmer only has to worry about the actual method implementation, rather    

than communication between objects. </p>    

    

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

    

<p class=BodyText> CORBA    

specifies a language called Interface Definition Language (IDL) for specifying    

an interface independent of the language or platform. The IDL is translated    

into a target language, and a framework of objects is created to allow two    

objects to talk with each other regardless of their location or language. </p>    

    

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

    

<p class=BodyText> At the    

heart of the framework are the stub and skeleton objects. In Figure 2, the    

calling object interacts with a stub object, which implements the interface of    

the remote object. The stub object bundles the method name and parameters into    

a message that can be sent over a network using a proprietary message standard,    

or Internet InterOperable Protocol (IIOP), to a receiving object called the    

skeleton. The skeleton object then un-bundles and calls the remote object. The    

remote object has no idea that it is being called remotely, and the client    

object has no idea that it is calling a remote object. The stub and skeleton    

objects act as an object bus to seamlessly connect the two objects over the    

network. </p>    

    

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

    

<p class=Captions><img width=330 height=209    

 src="images/cb200005rs_f_image001.gif" tppabs="http://www.cbuilderzine.com/features/2000/05/cb200005rs_f/cb200005rs_f_image001.gif"> <br>    

<b>Figure 2:</b> Message passing. </p>    

    

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

    

    

    

<p class=Subheads>Building a    

CORBA Application</p>    

    

<p class=BodyText> With the    

introduction of C++Builder 4/5, Inprise has created a tight integration between    

the IDE and VisiBroker. To build and run an application using CORBA and    

C++Builder 4/5, the following steps are required: </p>    

    

<p class=BodyText> 1) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Create    

a server project using the CORBA Server Wizard. </p>    

    

<p class=BodyText> 2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Define    

the interface using IDL. </p>    

    

<p class=BodyText> 3) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Implement    

the object using the CORBA Object Implementation Wizard. </p>    

    

<p class=BodyText> 4) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Create    

a client project using the CORBA Client Wizard. </p>    

    

<p class=BodyText> 5) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Run    

OSAgent. </p>    

    

<p class=BodyText> 6) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Run    

the server. </p>    

    

<p class=BodyText> 7) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    

Run    

the client. </p>    

    

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

    

<p class=BodyText> The    

following sections discuss each step in-depth, and are based on a simple    

customer object. </p>    

    

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

    

<p class=Subheads>Creating a    

CORBA Server Project</p>    

    

<p class=BodyText> The    

first step is to create a project group. This project group will house our    

server and client. To accomplish this, select File | Close All.    

Then select File | New, and select Project Group from the New page of the New    

dialog box. After saving the project group you've created, add a new project by    

selecting CORBA Server from the Multitier page of the New    

dialog box, to invoke the CORBA Server Wizard (see Figure 3). </p>    

    

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

    

<p class=Captions><img width=333 height=315    

 src="images/cb200005rs_f_image002.gif" tppabs="http://www.cbuilderzine.com/features/2000/05/cb200005rs_f/cb200005rs_f_image002.gif"> <br>    

<b>Figure 3: </b>The CORBA Server Wizard. </p>    

    

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

    

    

    

<p class=BodyText> The    

CORBA Server Wizard allows you to build servers from an existing IDL, or from a    

new IDL file. The application can be a Console Application (that does or does not use the VCL), or a Windows Application. Currently it doesn't allow one to    

write a server as an NT Service. Hopefully, in future versions the ability to    

make it a service will be included. In our example, the server will be a    

console application using the VCL, and a new IDL file will be created. When you    

click the OK button, a project with two files,    

the main cpp for the project and an IDL file, is created. Saving the (renamed)    

project and IDL files will show you the files in the Project Manager (see    

Figure 4). </p>    

    

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

    

<p class=Captions><img width=333 height=231    

 src="images/cb200005rs_f_image004.gif" tppabs="http://www.cbuilderzine.com/features/2000/05/cb200005rs_f/cb200005rs_f_image004.gif"> <br>    

<b>Figure 4:</b> The Project Manager after step 1. </p>    

    

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

    

    

    

<p class=BodyText> Be    

careful not to alter the CustServer.cpp file. This file will be maintained by    

the IDE and will be altered as implementation objects are added to the server.    

This is very similar to how forms are added when using the auto-create    

mechanism. This feature makes writing servers a snap using C++Builder 4/5 (see    

Figure 5). </p>    

    

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

    

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

main(<b>int</b> argc, <b>char</b>* argv[])</span></p>    

    

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

    

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

    

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

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<i> <span Class=CodeBlue>// Initialize the ORB and BOA. </span></i></span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;CORBA::ORB_var orb = CORBA::ORB_init(argc,    

argv); </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;CORBA::BOA_var boa =    

orb-&gt;BOA_init(argc, argv); </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<i> <span Class=CodeBlue>// Wait for incoming requests. </span></i></span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;boa-&gt;impl_is_ready();</span></p>    

    

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

    

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

style='mso-bidi-font-weight:normal'>const</b> CORBA::Exception&amp; e) </span></p>    

    

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

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;cerr &lt;&lt; e &lt;&lt; endl; </span></p>    

    

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<b> return</b>(1); </span></p>    

    

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

    

⌨️ 快捷键说明

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