View Single Post
  #1 (permalink)  
Old 11-01-2004
wwwtiger wwwtiger is offline
Registered User
 
 
Join Date: Oct 2004
Posts: 10
Is there a AMD demo project?

I just change printer example to use AMI/AMD,

interface Printer
{
["ami","amd"] void printString(string s,out string reply);
};

When use AMI it works, but use AMD following the guide from ICE manual, client program report :
printer failed: .\Connection.cpp:208: Ice::CommunicatorDestroyedException:
communicator object destroyed

server side code:
class Job : public IceUtil::Shared
{
public:
Job(const AMD_Printer_printStringPtr &,const ::std::string& );
void execute();
private:
bool setReply();
AMD_Printer_printStringPtr _cb;
string _s;
};
typedef IceUtil::Handle<Job> JobPtr;


Job::Job(const AMD_Printer_printStringPtr & cb,const ::std::string& s):_cb(cb), _s(s)
{
}

bool Job::setReply()
{
_s.append(" welcome to AMD!");
return true;
}

void Job::execute()
{
if(!setReply())
{
return;
}
_cb->ice_response(_s);
}


class PrinterI : virtual public Printer,virtual public IceUtil::Mutex
{
public:
virtual void printString_async(const AMD_Printer_printStringPtr &, const ::std::string&, const Ice::Current &);
private:
::std::list<JobPtr> _jobs;
};

void PrinterI:rintString_async(const AMD_Printer_printStringPtr & cb, const ::std::string& s, const Ice::Current &)
{
IceUtil::Mutex::Lock sync(*this);
JobPtr job = new Job(cb, s);
_jobs.push_back(job);
}

And I think AMD do not affect client code, so the client is the same code using AMI.

client code:
ic = Ice::initialize(argc, argv);
Ice::ObjectPrx base = ic->stringToProxy("SimplePrinter:default -p 10000");
PrinterPrx printer = PrinterPrx::checkedCast(base);
if (!printer)
throw "Invalid proxy";

AMI_Printer_printStringPtr cb = new AMI_Printer_printStringI;
printer->printString_async(cb, "Scott");



Is there something wrong in the code? Maybe I can fix the problem by myself if I can get a AMD demo project, but I can't find it in demos shifted with ICE.
Reply With Quote