コード例 #1
0
ファイル: calculator_server.cpp プロジェクト: psukys/dbus-cxx
int main()
{
  DBus::init();
  
  int ret;

  DBus::Dispatcher::pointer dispatcher = DBus::Dispatcher::create();

  DBus::Connection::pointer conn = dispatcher->create_connection(DBus::BUS_SESSION);
  
  // request a name on the bus
  ret = conn->request_name( "dbuscxx.example.calculator.server", DBUS_NAME_FLAG_REPLACE_EXISTING );
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) return 1;

  Examples::Calculator calculator;

  DBus::Example::CalculatorAdapter::pointer adapter = DBus::Example::CalculatorAdapter::create(&calculator);

  conn->register_object( adapter );

  std::cout << "Running" << std::flush;
  
  for (int i=0; i < 10; i++)
  {
    std::cout << "." << std::flush;
    sleep(1);
  }
  
  std::cout << std::endl;

  return 0;

}
コード例 #2
0
int main()
{
  DBus::init();

  DBus::Dispatcher::pointer dispatcher;
  dispatcher = DBus::Dispatcher::create();

  DBus::Connection::pointer connection;
  connection = dispatcher->create_connection( DBus::BUS_SESSION );

  //create an object proxy, which stands in for a real object.
  //a proxy exists over the dbus
  DBus::ObjectProxy::pointer object;
  object = connection->create_object_proxy("dbuscxx.quickstart_0.server", "/dbuscxx/quickstart_0");

  //a method proxy acts like a real method, but will go over the dbus
  //to do its work.
  DBus::MethodProxy<double,double,double>& add_proxy
    = *(object->create_method<double,double,double>("dbuscxx.Quickstart","add"));

  double answer;
  answer = add_proxy( 1.1, 2.2 );

  std::cout << "1.1 + 2.2 = " << answer << std::endl;

  return 0;
}
コード例 #3
0
int main()
{
  DBus::init();
  
  int ret;

  DBus::Dispatcher::pointer dispatcher = DBus::Dispatcher::create();

  DBus::Connection::pointer conn = dispatcher->create_connection(DBus::BUS_SESSION);
  
  // request a name on the bus
  ret = conn->request_name( "dbuscxx.example.calculator.server", DBUS_NAME_FLAG_REPLACE_EXISTING );
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) return 1;

  Inherited::pointer inherited = Inherited::create(0.0);

  inherited->signal_calculation().connect(sigc::ptr_fun(on_signal_calculation));

  conn->register_object( inherited );

  std::cout << "Running" << std::flush;
  
  for (int i=0; i < 10; i++)
  {
    std::cout << "." << std::flush;
    sleep(1);
  }
  
  std::cout << std::endl;

  return 0;

}
コード例 #4
0
ファイル: InBasket.cpp プロジェクト: Phoenox/lingtd
InBasket::InBasket() {

  //Connect to DBus
  DBus::init();
  m_dispatcher = DBus::Dispatcher::create();
  DBus::Connection::pointer connection = m_dispatcher->create_connection( DBus::BUS_SESSION );
  m_object = connection->create_object_proxy("org.lingtd", "/");
}
コード例 #5
0
ファイル: signal_emitter_2.cpp プロジェクト: psukys/dbus-cxx
int main()
{
  DBus::init();
  
  DBus::Connection::pointer connection = DBus::Connection::create( DBus::BUS_SESSION );

  DBus::signal<void,std::string>::pointer signal = connection->create_signal<void,std::string>("/test/signal/Object", "test.signal.Type", "Test");

  const char* sigvalue1 = "Hello";
  std::string sigvalue2("World");

  signal->connect( sigc::ptr_fun(callback) );

  signal->emit( sigvalue1 );
  connection->flush();

  signal->emit( sigvalue2 );
  connection->flush();

  usleep(250000);
}
コード例 #6
0
int main()
{
  int ret;

  DBus::init();
  
  DBus::Dispatcher::pointer dispatcher = DBus::Dispatcher::create();

  DBus::Connection::pointer conn = dispatcher->create_connection(DBus::BUS_SESSION);
  
  ret = conn->request_name( "dbuscxx.quickstart_0.server", DBUS_NAME_FLAG_REPLACE_EXISTING );
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) return 1;

  //create an object on us
  DBus::Object::pointer object = conn->create_object("/dbuscxx/quickstart_0");

  //add a method that can be called over the dbus
  object->create_method<double,double,double>("dbuscxx.Quickstart", "add", sigc::ptr_fun(add) );

  sleep(10);
  
  return 0;
}