Archived

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

server in the background

// My Ice-file CCU.ice:
"cpp:include:list"
module CCU {
["cpp:type:std::list<std::string>"] sequence<string> LIST;
["cpp:type:std::vector<std::string>"] sequence<string> VECTOR;
interface Crane {
void setCommand(string name,LIST parameter);
void setState(string name,LIST properties, VECTOR relations);
};
};
// end of CCU.ice

// My file CCUIS.h:
#include <Ice/Ice.h>
//#inclued <CCU_v1.h>
#include <CCU_v2.h>
#include <Command.h>

using namespace std;
using namespace CCU;

class CraneI : public Crane {
public:
// set command
virtual void setCommand(const ::std::string&,const ::CCU::LIST&, const ::Ice::Current&);
// set state
virtual void setState(const ::std::string&,const ::CCU::LIST&,const ::CCU::VECTOR& , const ::Ice::Current&);

static Ice::CommunicatorPtr _communicator;
static Ice::ObjectAdapterPtr _adapter;
};

class Server : virtual public Ice::Application{
public:
Server() {}
int run(int argc,char* argv[]) {
shutdownOnInterrupt();
CraneI::_adapter = communicator()->createObjectAdapter("Crane");
CraneI::_communicator = communicator();

Ice::ObjectPtr object = new CraneI;
CraneI::_adapter->add(object,communicator()->stringToIdentity("SimpleLogFile"));
CraneI::_adapter->activate();

cout << "******************************************************" << endl;
cout << "* shutting down with CTRL-C *" << endl;
cout << "******************************************************" << endl;

communicator()->waitForShutdown();
if (interrupted()) {
cerr << "\n" << endl;
cerr << "******************************************************" << endl;
cerr << "*" << appName() << ": received signal, shutting down. *" << endl;
cerr << "******************************************************" << endl;
}
return 0;
}
static Command _com;
};
// end of CCUIS.h

// My file Server.cpp:
#include <CCUIS.h>

int main(int argc, char* argv[]) {
Server s;
int status = s.main(argc,argv);
// What I have to do to print out "test" after s.main()???
cout << "test!" << endl;
return status;
}
// end of Server.cpp

What I have to do, to run my server in the background, that means, that
I want to go on working after "int status = s.main(argc, argv[])"??

Comments

  • xdm
    xdm La Coruña, Spain
    Hi Peter,
    What I have to do, to run my server in the background, that means, that
    I want to go on working after "int status = s.main(argc, argv[])"??

    I'm not sure what you want to do, but after application main returns the Ice::Application is gone. Why you don't want to start the works inside your Application class implementation, this is the way the class is intended to be used.

    If you are looking how to run the application as a Unix daemon or a Windows service (run on the background). The easy is to subclass Ice::Service instead of Ice::Application, see http://www.zeroc.com/doc/Ice-3.3.1/manual/Cpps.9.3.html#70646

    Also note that Ice::Application and Ice::Service are only helper classes , if the classes doesn't do what you need, is easier to initialize the run time your self, see cpp/demo/Ice/minimal/ included in Ice distribution for an example on how to do that.

    Cheers,
    José
  • Subscriber in background

    Hi

    I understand that the Ice::Application base class implements some code to make things easier but I don't find the invariants for the Ice class methods in the reference manual.

    I adapted one of the IceStorm demos and it works fine. Now I want to use the subscriber in a GUI application. I created a method which does the subscription. I get the communicator with:
    communicator = Ice.Util.initialize(args);
    

    I then try to get the topic manager proxy:
    IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(
                communicator.propertyToProxy("TopicManager.Proxy"));
    
    which returns null. I assume the problem is with the fact that the communicator does not know what the config file is which contains the TopicManager.Proxy property.

    So, my question is; how do you "load" the properties (or specify the config file) if you are not implementing the subscriber logic inside an overloaded run() method?

    Thanks.
  • xdm
    xdm La Coruña, Spain
    Hi Peter,

    you could do something like
    Ice.InitializationData id = new Ice.InitializationData();
    id.properties = Ice.Util.createProperties(args);
    
    Ice.Communicator communicator = Ice.Util.initialize(args, id);
    

    Here properties should be loaded from the file designed by --Ice.Config command line argument.

    You could also use properties load method, to load properties from a different file.

    see also http://www.zeroc.com/doc/Ice-3.3.1/manual/Properties.31.8.html to know more about how to use properties programmatically.


    Let's us know if you need further help with that.

    Cheers,
    José
  • Thanks José.

    Sorry, I posted on an existing thread (by Peter) because it was closely related to my question.

    I will try it out.

    Thanks,
    Kobus.