conexus logo

messagequeue_server.cpp

Conexus::MessageQueue example server

/***************************************************************************
 *   Copyright (C) 2007 by Rick L. Vinyard, Jr.                            *
 *   rvinyard@cs.nmsu.edu                                                  *
 *                                                                         *
 *   This file is part of the conexus library.                             *
 *                                                                         *
 *   The conexus library is free software; you can redistribute it and/or  *
 *   modify it under the terms of the GNU General Public License version 3 *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 *   The conexus library is distributed in the hope that it will be        *
 *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
 *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
 *   General Public License for more details.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#include <conexus.h>
#include <iostream>

void print_data( const Conexus::Data d );

int main( int argc, char *argv[] )
{
  int run_time = 20;

  Conexus::init();

  Conexus::MessageQueue::pointer mq = Conexus::MessageQueue::create("/test_queue");

  mq->set_unlink_on_destruction();

  mq->signal_data().connect(sigc::ptr_fun(&print_data));

  mq->start();

  // Set up a loop that will run and print the time every 5
  // seconds. Since the server is threaded, the sleep(1) call will not effect
  // the servicing thread.
  std::cout << "Starting..." << std::endl;
  for (int i=0; i <= run_time; i++) {
    if (i%5 == 0)
      std::cout << "Time: " << i << std::endl;
    sleep(1);
  }
  std::cout << "Time: " << run_time << std::endl;

  // Stop the server and prepare for shutdown
  mq->stop();

  return 0;

}

void print_data( const Conexus::Data d )
{
  std::cout << "data: ";
  for ( unsigned i = 0; i < d.size(); i++ )
    std::cout << d[ i ];
  std::cout << std::endl;
}

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8