Connecting a Component to a View Server

You can connect a component to a view server either from the component or from the server.

From Component to Server

Once the process is initialized, the component can be connected to a view server using the static member function Connect, which takes the server name and the server host name as its parameters:

   IlsString serverName=...;

   IlsString serverHost=...;

   IlsMvComponent* comp=IlsMvComponent::Connect(serverName,serverHost);

   if (!comp) {

      cerr << "Connection to server has failed" << endl;

      ....

   }

From Server to Component

It is sometimes necessary for a server to connect to a component. This can be done by the static member function IlsMvProcess::Connect. The component must have been assigned a name by the option -ilsn or the static member function SetName described in Naming a Distributed Server. The connection could be implemented as follows:

   IlsString compName=...;

   IlsString compHost=...;

   IlsMvComponentItf* compItf=0;

   IlsMvEndPoint* endPoint=

           IlsMvProcess::Connect(compName,compHost,IlsFalse);

   if (!endPoint) {

      cerr << "Connection to server has failed" << endl;

      ....

   }else {

      compItf=IlsMvComponentItf::Narrow(*endPoint);

      assert(compItf);

   }

The third argument IlsFalse passed to Connect indicates that the process you try to connect is a component and not a server. However, this function can be used to connect a server by setting the Boolean argument to IlsTrue. The result of the function is a pointer to an object of type IlsMvEndPoint, which is the base class for both components (instances of the subclass IlsMvComponent) and component interfaces (instances of the class IlsMvComponentItf). In our example, the pointer to the component interface is obtained by narrowing the returned IlsMvEndPoint object.

Connection through Command Line Options

Server options can also be used to connect a component to a server. For instance:

myComponent -ilsc myServer[@server_host]

In that case, you must call the static function DoConnect before starting the event loop:

int main(int argc, char **argv)

{

if (!IlsOrbixMvProcess::Initialize(argc,argv)){

cerr << "Initialization of component failed" << endl;

return 1;

}

// Views initializations...

  int failCount=IlsMvProcess::DoConnect();

if (failCount){

cerr << "Fails to connect " << failCount << " view server(s)"

<< endl;

}

IlvMainLoop();

return 0;

}

Connection through the Connection Panel

When developing a graphical application using Views, you can use the connection panel supplied in the Server library mvconpan to connect view servers.

To do so, you must initialize the connection panel as follows:

#include <ilmvpan/vwconpan.h>

 

int

main(int argc, char **argv)

{

...

IlsVwConnectionPanel::Initialize("*");

}

The argument passed to the Initialize function is a full name or a regular expression (using the wildcards “?” to match any character and “*” to match any string). This argument is used to filter the view types that are listed when an object label is selected. the filtering depends on the representation type they instantiate.

Important!

The default representation type is IlsRepresentation—or the derived type IlsSwRepresentation for the view types that use the Server/Views mapping. Therefore, the connection panel for a Server/Views component usually initializes the connection panel like this:

IlsVwConnectionPanel::Initialize("IlsSwRepresentation");