Archived
This forum has been archived. Please start a new discussion on GitHub.
when load the initialize() function in the server from demo\Ice\plugin?

in Help Center
when I run the server in the ice demo Ice\plugin ,I find initialize() function which is in the helloplugin34d.dll ,is called but don't know when it is called.
helloplugin code as follow:
///////////////////////////////////////////////
class HelloPluginI : public Ice::Plugin
{
public:
HelloPluginI(const Ice::CommunicatorPtr& communicator) :
_communicator(communicator)
{cout<<"通信器初始化!"<<endl;
}
void
initialize()
{
cout<<"hello适配器初始化!"<<endl;
Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapter("Hello");
adapter->add(new HelloI, _communicator->stringToIdentity("hello"));
adapter->activate();
}//为什么会调用这个函数?
void
destroy()
{
cout<<"销毁初始化!"<<endl;
}
private:
Ice::CommunicatorPtr _communicator;
};
};
extern "C"
{
ICE_DECLSPEC_EXPORT ::Ice::Plugin*
createHello(const Ice::CommunicatorPtr& communicator, const string& name, const Ice::StringSeq& args)
{
return new HelloPluginI(communicator);
}
}
/////////////////////////////////////////////////////
the server code as follow:
////////////////////////////////////////////////////
#include <Ice/Ice.h>
using namespace std;
class PluginServer : public Ice::Application
{
public:
virtual int
run(int argc, char* argv[])
{
if(argc > 1)
{
cerr << appName() << ": too many arguments" << endl;
return EXIT_FAILURE;
}
communicator()->waitForShutdown();
return EXIT_SUCCESS;
}
};
int
main(int argc, char* argv[])
{
PluginServer app;
return app.main(argc, argv, "config.server");
}
//////////////////////////////////////////////////////
the config.server code as follow :
//////////////////////////////////////////////////////
#
# Warn about connection exceptions
#
Ice.Warn.Connections=1
#
# Network Tracing
#
# 0 = no network tracing
# 1 = trace connection establishment and closure
# 2 = like 1, but more detailed
# 3 = like 2, but also trace data transfer
#
Ice.Trace.Network=1
#
# Protocol Tracing
#
# 0 = no protocol tracing
# 1 = trace protocol messages
#
#Ice.Trace.Protocol=1
#
# Logger Plugin Configuration
#
Ice.Plugin.Logger=LoggerPlugin:createLogger
#
# Hello Plugin Configuration
#
Ice.Plugin.Hello=HelloPlugin:createHello
Hello.Endpoints=tcp -p 10000
//////////////////////////////////////////
I trace the sever runing ,when the code run
///////////////////////////////////////////
class PluginServer : public Ice::Application
{
public:
virtual int
run(int argc, char* argv[])
//////////////////////////////////////////
I find the initialize() function has been called !but I don't know when it is called ?
could you tell me ?
thank you very much ..
helloplugin code as follow:
///////////////////////////////////////////////
class HelloPluginI : public Ice::Plugin
{
public:
HelloPluginI(const Ice::CommunicatorPtr& communicator) :
_communicator(communicator)
{cout<<"通信器初始化!"<<endl;
}
void
initialize()
{
cout<<"hello适配器初始化!"<<endl;
Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapter("Hello");
adapter->add(new HelloI, _communicator->stringToIdentity("hello"));
adapter->activate();
}//为什么会调用这个函数?
void
destroy()
{
cout<<"销毁初始化!"<<endl;
}
private:
Ice::CommunicatorPtr _communicator;
};
};
extern "C"
{
ICE_DECLSPEC_EXPORT ::Ice::Plugin*
createHello(const Ice::CommunicatorPtr& communicator, const string& name, const Ice::StringSeq& args)
{
return new HelloPluginI(communicator);
}
}
/////////////////////////////////////////////////////
the server code as follow:
////////////////////////////////////////////////////
#include <Ice/Ice.h>
using namespace std;
class PluginServer : public Ice::Application
{
public:
virtual int
run(int argc, char* argv[])
{
if(argc > 1)
{
cerr << appName() << ": too many arguments" << endl;
return EXIT_FAILURE;
}
communicator()->waitForShutdown();
return EXIT_SUCCESS;
}
};
int
main(int argc, char* argv[])
{
PluginServer app;
return app.main(argc, argv, "config.server");
}
//////////////////////////////////////////////////////
the config.server code as follow :
//////////////////////////////////////////////////////
#
# Warn about connection exceptions
#
Ice.Warn.Connections=1
#
# Network Tracing
#
# 0 = no network tracing
# 1 = trace connection establishment and closure
# 2 = like 1, but more detailed
# 3 = like 2, but also trace data transfer
#
Ice.Trace.Network=1
#
# Protocol Tracing
#
# 0 = no protocol tracing
# 1 = trace protocol messages
#
#Ice.Trace.Protocol=1
#
# Logger Plugin Configuration
#
Ice.Plugin.Logger=LoggerPlugin:createLogger
#
# Hello Plugin Configuration
#
Ice.Plugin.Hello=HelloPlugin:createHello
Hello.Endpoints=tcp -p 10000
//////////////////////////////////////////
I trace the sever runing ,when the code run
///////////////////////////////////////////
class PluginServer : public Ice::Application
{
public:
virtual int
run(int argc, char* argv[])
//////////////////////////////////////////
I find the initialize() function has been called !but I don't know when it is called ?
could you tell me ?
thank you very much ..
0
Comments
-
thank you very much !
thank you very much !
I have read the article.0