However , if slice2cpp do like this:
Code:
------------code1(Suppose it is placed in IncomingAsync.h)
namespace IceInternal
{
class AMDThreadPool
{
//Logic:
// 1.The AMDTheadPool has a work queue of AMDJob and runs in a Leader-Follower mode.
// 2.A single thread just get one AMDJob off the queue, then call it's AMDJob::execute() method.
}
class AMDJob
{
public:
int registerWithAMDThreadPool()
{
//Logic:
// 1.put self into AMDThreadPool's work queue
}
virtual void execute() = 0;
}
}
------------code2(PrinterAMD.h)
namespace IceAsync
{
namespace Demo
{
class AMD_PrinterAMD_printString : public ::Demo::AMD_PrinterAMD_printString, public ::IceInternal::IncomingAsync,
public ::IceInternal::AMDJob
{
public:
AMD_PrinterAMD_printString(::IceInternal::Incoming&);
virtual void ice_response(::Ice::Int, const ::std::string&);
virtual void ice_exception(const ::Ice::Exception&);
virtual void ice_exception(const ::std::exception&);
virtual void ice_exception();
void cacheData(Ice::Int id, const Ice::Current current, PrinterAMD *ptr);
{
//1.cache data
__id = id;
__current = current;
__ptr = ptr;
//2.register with AMD thread pool
registerWithAMDThreadPool();
}
virutal void execute()
{
try
{
//call the real business logic
__ptr->printString_async(this, __id, __name, __ret,__current);
}
catch (...)
{
ice_exception(...) //Send a exception to the client
}
ice_response(...); //Send a normal response to the client
}
protected:
//The class members is corresponding to the params of the printString operation. dynamic
//Input parameters
Ice::Int __id;
Ice::Current __current;
PrinterAMD* __ptr;
//Output parameters and return value
::std::string __name;
::Ice::Int __ret;};
}
}
------------code3(PrinterAMD.h)
namespace Demo
{
class PrinterAMD : virtual public ::Ice::Object
{
public:
//...
virtual void printString_async(const ::Demo::AMD_PrinterAMD_printStringPtr&, ::Ice::Int,
::Ice::Int &, ::std::string&, const ::Ice::Current& = ::Ice::Current()) = 0;
//...
};
}
------------code4(PrinterAMD.cpp)
::IceInternal::DispatchStatus
Demo::PrinterAMD::___printString(::IceInternal::Incoming& __in, const ::Ice::Current& __current)
{
::IceInternal::BasicStream* __is = __in.is();
::Ice::Int id;
__is->read(id);
::Demo::AMD_PrinterAMD_printStringPtr __cb = new IceAsync::Demo::AMD_PrinterAMD_printString(__in);
try
{
//printString_async(__cb, id, __current);
__cb.cacheData(id, __current, this);
}
catch(const ::Ice::Exception& __ex)
{
//...
}
return ::IceInternal::DispatchAsync;
}
------------code5(PrinterAMDI.cpp; programmers' code)
Programmers can just write a PrinterAMDI implementation class as usual like this:
class PrinterAMDI: public PrinterAMD
{
virtual void printString_async(const ::Demo::AMD_PrinterAMD_printStringPtr&, ::Ice::Int,
::Ice::Int &, ::std::string&,
const ::Ice::Current& = ::Ice::Current())
{
//we can write business logic here as usual.
}
}
If slice2cpp do like above code, then programmers need only write code5. This is very simple.