Exemple #1
0
ObserverTopic::ObserverTopic(const IceStorm::TopicManagerPrx& topicManager, const string& name, Ice::Long dbSerial) :
    _logger(topicManager->ice_getCommunicator()->getLogger()), _serial(0), _dbSerial(dbSerial)
{
    for(int i = 0; i < static_cast<int>(sizeof(encodings) / sizeof(Ice::EncodingVersion)); ++i)
    {
        ostringstream os;
        os << name << "-" << Ice::encodingVersionToString(encodings[i]);
        IceStorm::TopicPrx t;
        try
        {
            t = topicManager->create(os.str());
        }
        catch(const IceStorm::TopicExists&)
        {
            t = topicManager->retrieve(os.str());
        }

        //
        // NOTE: collocation optimization needs to be turned on for the
        // topic because the subscribe() method is given a fixed proxy
        // which can't be marshalled.
        //
        _topics[encodings[i]] = t->ice_collocationOptimized(true);
        _basePublishers.push_back(
            t->getPublisher()->ice_collocationOptimized(false)->ice_encodingVersion(encodings[i]));
    }
}
Exemple #2
0
serverI::serverI(char* ipToSet, char *portToSet){

	port = portToSet;
	ip = ipToSet;
	ic = Ice::initialize();

	cout<<"----- Initialisation des fichiers audio :";
	if(initFiles())
		cout<<" OK"<<endl;	
	else{
		cerr << " Erreur" << endl;
		exit(1);
	}
        	
	cout<<"----- Initialisation du Topic :";

	// PREPARE TOPIC FOR PUBLISHING
	string topicName = "serv";
	
	Ice::ObjectPrx obj = ic->stringToProxy("server/TopicManager:tcp -h "+ip+" -p 10000");
	IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(obj);
	if(!manager)
    	{

        exit(1);
    	}
	IceStorm::TopicPrx topic;
    try
    {
	   cout<<"OK"<<endl;
        topic = manager->retrieve(topicName);
    }
    catch(const IceStorm::NoSuchTopic&)
    {
        try
        {
		  cout<<"OK"<<endl;
            topic = manager->create(topicName);
        }
        catch(const IceStorm::TopicExists&)
        {
		  cout<<"Error"<<endl;
            exit(1);
        }
	}
	
    Ice::ObjectPrx publisher = topic->getPublisher();
    publisher = publisher->ice_oneway();
    serv = MonitorPrx::uncheckedCast(publisher);

    cout<<"----- Lancement du serveur "<<endl;
    initStreaming();
}
Exemple #3
0
bool Publisher::Startup(void)
{
    this->IceInitialize();

    IceStorm::TopicManagerPrx manager;
    try {
        manager = IceStorm::TopicManagerPrx::checkedCast(this->IceCommunicator->propertyToProxy("TopicManager.Proxy"));
    } catch (const Ice::ConnectionRefusedException & e) {
        SCLOG_ERROR << PUBLISHER_INFO << "Failed to initialize IceStorm.  Check if IceBox is running: " << e.what() << std::endl;
        return false;
    }

    if (!manager) {
        SCLOG_ERROR << PUBLISHER_INFO << "Invalid proxy" << std::endl;
        return false;
    }

    // Retrieve the topic.
    IceStorm::TopicPrx topic;
    try {
        topic = manager->retrieve(this->TopicName);
    } catch(const IceStorm::NoSuchTopic&) {
        try {
            topic = manager->create(this->TopicName);
        }
        catch(const IceStorm::TopicExists&) {
            SCLOG_ERROR << PUBLISHER_INFO << "Topic not found. Try again." << std::endl;
            return false;
        }
    }

    // Get the topic's publisher object, and create topic proxy
    Ice::ObjectPrx publisher = topic->getPublisher();

    // Get the topic's publisher object, and create a proper proxy depending on
    // the topic.
    switch (this->Topic) {
    case Topic::CONTROL:
        PublisherControl = ControlPrx::uncheckedCast(publisher);
        break;
    case Topic::DATA:
        PublisherData = DataPrx::uncheckedCast(publisher);
        break;
    default:
        SCASSERT(false);
    }

    //BaseType::Startup();

    return true;
}
Exemple #4
0
int
Publisher::run(int argc, char* argv[])
{
    Ice::PropertiesPtr properties = communicator()->getProperties();

    IceStorm::TopicManagerPrx manager = 
        IceStorm::TopicManagerPrx::checkedCast(communicator()->stringToProxy("DemoIceStorm/TopicManager"));
    if(manager == 0)
    {
        cerr << appName() << ": no topic manager found, make sure application was deployed." << endl;
        return EXIT_FAILURE;
    }

    string topicName = "time";
    if(argc != 1)
    {
        topicName = argv[1];
    }

    IceStorm::TopicPrx topic;
    try
    {
        topic = manager->retrieve(topicName);
    }
    catch(const IceStorm::NoSuchTopic&)
    {
        cerr << appName() << ": topics not created yet, run subscriber." << endl;
        return EXIT_FAILURE;
    }

    //
    // Get the topic's publisher object, and configure a Clock proxy
    // with per-request load balancing.
    //
    ClockPrx clock = ClockPrx::uncheckedCast(topic->getPublisher()->ice_oneway()->ice_connectionCached(false));

    try
    {
        while(true)
        {
            clock->tick(IceUtil::Time::now().toDateTime());
            IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
        }
    }
    catch(const Ice::CommunicatorDestroyedException&)
    {
        // Ignore
    }

    return EXIT_SUCCESS;
}
Exemple #5
0
CounterI::CounterI(const IceStorm::TopicPrx& topic) :
    _value(0),
    _topic(topic),
    _publisher(CounterObserverPrx::uncheckedCast(topic->getPublisher()))
{
}
Exemple #6
0
int Producer::run(int argc, char* argv[])
{
    EnabledMap::iterator it;

    IceUtil::Mutex::Lock broadcastLock(broadcastMutex);
    broadcastLock.release();

    // start up Ice server
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("ImageProvider", PRODUCER_ENDPOINT);
    Ice::Identity id = communicator()->stringToIdentity("ImageProvider");
    adapter->add(this, id);
    adapter->activate();

    // get topic manager
    topicManager = IceStorm::TopicManagerPrx::checkedCast(communicator()->stringToProxy(TOPIC_MANAGER));

    // get topic proxies to publish to
    IceStorm::TopicPrx embeddedTopicPrx;
    IceStorm::TopicPrx sharedMemoryTopicPrx;
    try
    {
        embeddedTopicPrx = topicManager->retrieve("ImageReceiverEmbedded");
    }
    catch (const IceStorm::NoSuchTopic&)
    {
        embeddedTopicPrx = topicManager->create("ImageReceiverEmbedded");
    }
    try
    {
        sharedMemoryTopicPrx = topicManager->retrieve("ImageReceiverSharedMemory");
    }
    catch (const IceStorm::NoSuchTopic&)
    {
        sharedMemoryTopicPrx = topicManager->create("ImageReceiverSharedMemory");
    }

    embeddedTopic = ImageReceiverEmbeddedPrx::uncheckedCast(embeddedTopicPrx->getPublisher()->ice_oneway());
    sharedMemoryTopic = ImageReceiverSharedMemoryPrx::uncheckedCast(sharedMemoryTopicPrx->getPublisher()->ice_oneway());

    while (!communicator()->isShutdown())
    {
        // broadcast data
        broadcastLock.acquire();

        for (it = broadcastEnabled.begin(); it != broadcastEnabled.end(); ++it)
        {
            if (it->second > 0)
            {
                // TODO: broadcast correct image type based on it->first.second
                switch (it->first.first)
                {
                    case Embedded:
                        embeddedTopic->receiveImageEmbedded(Blob(), it->first.second);
                    break;

                    case SharedMemory:
                        sharedMemoryTopic->receiveImageSharedMemory(SharedMemorySegment(), it->first.second);
                    break;
                }
            }
        }

        broadcastLock.release();

        // "wait" for next image
        IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(30)); // ~30 images/second
    }

    return 0;
}
Exemple #7
0
int
Publisher::run(int argc, char* argv[])
{
    enum Option { None, Datagram, Twoway, Oneway };
    Option option = None;
    string topicName = "time";
    int i;

    for(i = 1; i < argc; ++i)
    {
        string optionString = argv[i];
        Option oldoption = option;
        if(optionString == "--datagram")
        {
            option = Datagram;
        }
        else if(optionString == "--twoway")
        {
            option = Twoway;
        }
        else if(optionString == "--oneway")
        {
            option = Oneway;
        }
        else if(optionString.substr(0, 2) == "--")
        {
            usage(argv[0]);
            return EXIT_FAILURE;
        }
        else
        {
            topicName = argv[i++];
            break;
        }

        if(oldoption != option && oldoption != None)
        {
            usage(argv[0]);
            return EXIT_FAILURE;
        }
    }

    if(i != argc)
    {
        usage(argv[0]);
        return EXIT_FAILURE;
    }

    IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(
        communicator()->propertyToProxy("TopicManager.Proxy"));
    if(!manager)
    {
        cerr << appName() << ": invalid proxy" << endl;
        return EXIT_FAILURE;
    }

    //
    // Retrieve the topic.
    //
    IceStorm::TopicPrx topic;
    try
    {
        topic = manager->retrieve(topicName);
    }
    catch(const IceStorm::NoSuchTopic&)
    {
        try
        {
            topic = manager->create(topicName);
        }
        catch(const IceStorm::TopicExists&)
        {
            cerr << appName() << ": temporary failure. try again." << endl;
            return EXIT_FAILURE;
        }
    }

    //
    // Get the topic's publisher object, and create a Clock proxy with
    // the mode specified as an argument of this application.
    //
    Ice::ObjectPrx publisher = topic->getPublisher();
    if(option == Datagram)
    {
        publisher = publisher->ice_datagram();
    }
    else if(option == Twoway)
    {
        // Do nothing.
    }
    else if(option == Oneway || option == None)
    {
        publisher = publisher->ice_oneway();
    }
    
    ClockPrx clock = ClockPrx::uncheckedCast(publisher);

    cout << "publishing tick events. Press ^C to terminate the application." << endl;
    try
    {
        while(true)
        {
            clock->tick(IceUtil::Time::now().toDateTime());
            IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
        }
    }
    catch(const Ice::CommunicatorDestroyedException&)
    {
        // Ignore
    }

    return EXIT_SUCCESS;
}
Exemple #8
0
int
Publisher::run(int argc, char* argv[])
{
    IceUtil::Options opts;
    opts.addOpt("", "datagram");
    opts.addOpt("", "twoway");
    opts.addOpt("", "oneway");

    IceUtil::Options::StringVector remaining;
    try
    {
        remaining = opts.parse(argc, (const char**)argv);
    }
    catch(const IceUtil::BadOptException& e)
    {
        cerr << argv[0] << ": " << e.reason << endl;
        return EXIT_FAILURE;
    }

    IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(
        communicator()->propertyToProxy("IceStorm.TopicManager.Proxy"));
    if(!manager)
    {
        cerr << appName() << ": invalid proxy" << endl;
        return EXIT_FAILURE;
    }

    string topicName = "time";
    if(!remaining.empty())
    {
        topicName = remaining.front();
    }

    //
    // Retrieve the topic.
    //
    IceStorm::TopicPrx topic;
    try
    {
        topic = manager->retrieve(topicName);
    }
    catch(const IceStorm::NoSuchTopic&)
    {
        try
        {
            topic = manager->create(topicName);
        }
        catch(const IceStorm::TopicExists&)
        {
            cerr << appName() << ": temporary failure. try again." << endl;
            return EXIT_FAILURE;
        }
    }

    //
    // Get the topic's publisher object, and create a Clock proxy with
    // the mode specified as an argument of this application.
    //
    Ice::ObjectPrx publisher = topic->getPublisher();
    int optsSet = 0;
    if(opts.isSet("datagram"))
    {
        publisher = publisher->ice_datagram();
        ++optsSet;
    }
    else if(opts.isSet("twoway"))
    {
        // Do nothing.
        ++optsSet;
    }
    else if(opts.isSet("oneway") || optsSet == 0)
    {
        publisher = publisher->ice_oneway();
        ++optsSet;
    }
    if(optsSet != 1)
    {
        usage(appName());
        return EXIT_FAILURE;
    }
    ClockPrx clock = ClockPrx::uncheckedCast(publisher);

    cout << "publishing tick events. Press ^C to terminate the application." << endl;
    try
    {
        while(true)
        {
            clock->tick(IceUtil::Time::now().toDateTime());
            IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
        }
    }
    catch(const Ice::CommunicatorDestroyedException&)
    {
        // Ignore
    }

    return EXIT_SUCCESS;
}