Archived

This forum has been archived. Please start a new discussion on GitHub.

Create Proxy on client side with identity and category for ServantLocator

Hi,

I have just read about Ice Servant Locators and tried to implement one to test it.
So here is my implementation:

MyLocator.h
#ifndef _MYLOCATOR_H_
#define _MYLOCATOR_H_

#include <Ice/Ice.h>
#include <vector>

using namespace std;

class MyLocator : public virtual Ice::ServantLocator
{
public:
	MyLocator();
	virtual Ice::ObjectPtr locate( const Ice::Current& c,
									Ice::LocalObjectPtr& cookie );

	virtual void finished( const Ice::Current& c,
							const Ice::ObjectPtr& servant,
							const Ice::LocalObjectPtr& cookie );

	virtual void deactivate( const std::string &category );
private:
	vector<string> _myids;
};
#endif _MYLOCATOR_H_


MyLocator.cpp
#include "MyLocator.h"
#include "LocatorTestI.h"

using namespace LocatorTest;
using namespace std;

MyLocator::MyLocator()
{
	_myids.push_back("id0");
	_myids.push_back("id5");
	_myids.push_back("id10");
}

Ice::ObjectPtr
MyLocator::locate(const Ice::Current &c, Ice::LocalObjectPtr &cookie)
{
	string name = c.id.name;

	vector<string>::iterator it;
	for( it = _myids.begin(); it != _myids.end(); it++ )
		if( (*it) == name )
			return new LocatorTestI;
	
	return 0;
}

void 
MyLocator::finished(const Ice::Current &c, const Ice::ObjectPtr &servant, const Ice::LocalObjectPtr &cookie)
{
}

void
MyLocator::deactivate(const std::string &category)
{
}

Server.cpp
#include <Ice/Ice.h>
#include <Ice/Application.h>
#include <iostream>

#include "LocatorTestI.h"
#include "MyLocator.h"

using namespace std;

class MyApp : public virtual Ice::Application
{
public:
	virtual int run( int, char *[] );
private:
	Ice::ObjectAdapterPtr _adapter;
};

int 
main( int argc, char *argv[] )
{
	MyApp app;
	return app.main( argc, argv );
}

int
MyApp::run(int, char *[])
{
	_adapter = communicator()->createObjectAdapterWithEndpoints("myAdapter", "default -p 10000");
	MyLocator *locator = new MyLocator();
	_adapter->addServantLocator(locator, "myids");
	_adapter->activate();
	communicator()->waitForShutdown();
	return 0;
}

And my question is: How to create proxy on client side with Identity such as:
id.name="id0"
id.category="myids"

Comments

  • dwayne
    dwayne St. John's, Newfoundland
    You can specify both category and name in your proxy string. For example

    communicator->stringToProxy("category/name:tcp -p 10000 -h 127.0.0.1");

    changing category and name appropriately. In your case "myids/id0".