Archived

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

How do I write a c++ server for the slice containing interface and class?

Hi,
Following is the slice :

module MyModule
{
class MyClass1
{
void display(string s);
};
interface UseMyClass
{
void DisplayMessage(MyClass1 obj);
}
};

I want to display a string using the method DisplayMessage which takes the MyClass1 object.

I have written the server as shown below:

using namespace std;
using namespace MyModule;


class UseClassI : public UseMyClass
{
public:
virtual void DisplayMessage(MyModule::MyClass1 & obj ,
const Ice::Current &);
};

void UseClassI :: DisplayMessage(MyClass1& obj,const Ice::Current &)
{
obj.display("hi");
}

void MyClass1::display(const string & s,const Ice::Current &)
{
cout<<s<<endl;
}



int main(int argc, char* argv[])
{
int status = 0;
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter= ic->createObjectAdapterWithEndpoints("UseClassAdapter", "default -p 10000");
Ice::ObjectPtr object = new UseClassI;
adapter->add(new UseClassI,Ice::stringToIdentity("UseClassServer"));
adapter->activate();
ic->waitForShutdown();
} catch (const Ice::Exception & e) {
cerr << e << endl;
status = 1;
} catch (const char * msg) {
cerr << msg << endl;
status = 1;
}
if (ic) {
try {
ic->destroy();
} catch (const Ice::Exception & e) {
cerr << e << endl;
status = 1;
}
}
return status;
}


I am getting the error message as "Cannot instantiate UseClassI".

Could you please help me in how to write this server so that in the client program I can access the DisplayMessage method?

Comments

  • matthew
    matthew NL, Canada
    Before we can provide assistance you must fill out your signature as described in this post http://www.zeroc.com/vbulletin/showthread.php?p=7297#post7297
  • How do I write a c++ server for the slice containing interface and class?

    Hi,
    Could you please help me in how to write this server?.I have already updated my signature.
  • Post More Info

    Hi,

    I suppose you are getting a compile-time error. If you could provide the exact error message, it would be most helpful.

    Cheers,
  • matthew
    matthew NL, Canada
    Your signature also contains insufficient information for us to help you. As detailed in the post you need to provide:

    * Your full name (no nicknames please).
    * The name of your company or organization (such as universities), including a Web address (URL).
    * The name(s) of the Ice project(s) you are working on, if possible with URL.