Exemple #1
0
int main(int argc, char* argv[]) {
  struct sigaction sa;
  sigemptyset(&sa.sa_mask);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  sigaction( SIGPIPE, &sa, 0 );

  Communicator* comm = Communicator::instance();
  if (comm->init() == -1)
    return -1;

  // Identity's arg must correspond to the class name in Hello.idl
  // Endpoind's arg: protocal, ip, port of the server end
  // in case of async call, timeout option is not needed
  Reference ref (comm, Identity("MyHello"), Endpoint("TCP", "127.0.0.1", 3000));
  IcmProxy::demo::MyHello myHello;
  myHello.setReference (&ref);

  unsigned long u =  1024ul * 1024 * 1024 * 12;

  // invoke async calls
  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async", u);
  myHello.sayBye_async(new AMI_MyHello_sayByeI, "Bye, async");

  // run() will enter a cycle to wait and process server reply, callback classes's response() will be invoked automatically
  // so usually this can be put into a new created thread 
  comm->run();

  return 0;
}
Exemple #2
0
int
main (int argc, char* argv[])
{
  Communicator* comm = Communicator::instance();
  if (comm->init (true) == -1)
    return -1;

  Reference ref (comm, Identity("MyHello"), Endpoint("TCP", "127.0.0.1", 3000));
  IcmProxy::demo::MyHello myHello;
  myHello.setReference (&ref);

  for (int i = 0; i < 10; i++) {
    Short u = 10 + i;
    Long v = 1000 + i;
    std::ostringstream ss;
    ss << "hello, world from " << i;
    string ret = myHello.sayHello (ss.str(), u, v);
	if ( IcmProxy::IsCallSuccess() ) { 
		std::cout<<"call success. errno:"<<errno<<std::endl;
	} else {
		std::cout<<"call failed. errno:"<<errno<<std::endl;
	}
    if (ret != "") {
      std::cout << "ret:" << ret << std::endl;
    } else {
      //err process
    }
  }

  return 0;
}
Exemple #3
0
int
main (int argc, char* argv[])
{
  Communicator* comm = Communicator::instance();
  if (comm->init () == -1)
    return -1;
  
  Endpoint endpoint ("TCP", "", 3000);
  ObjectAdapter* oa = comm->createObjectAdapterWithEndpoint ("MyHello", &endpoint);
  Object* object = new demo::MyHelloI;
  oa->add (object, "MyHello");

  comm->run ();

  return 0;
}
Exemple #4
0
int
main (int argc, char* argv[])
{
  Communicator* comm = Communicator::instance();
  if (comm->init () == -1)
    return -1;

  demo::DelayResponse* task = new demo::DelayResponse;

  Endpoint endpoint ("TCP", "", 3000);
  ObjectAdapter* oa = comm->createObjectAdapterWithEndpoint ("MyHello", &endpoint);

  demo::AmhMyHelloI*  amh = new demo::AmhMyHelloI;
  amh->set(task);
  oa->add (amh, "MyHello");

  task->activate();

  comm->run ();

  delete task;

  return 0;
}
Exemple #5
0
int
Subscriber::run(int argc, char* argv[]) {
  Communicator* comm = Communicator::instance();
  if (comm->init (true) == -1)
    return -1;

  Reference ref (comm, Identity("TopicManager"), Endpoint("TCP", "127.0.0.1", 5555));
  IcmProxy::IcmMsg::TopicManager topicManager;
  topicManager.setReference (&ref);

  ObjectAdapter* adapter = comm->createObjectAdapterWithEndpoint("Subscriber", "127.0.0.1 8888");
  IcmProxy::Object* networkProxy = adapter->add(new NetworkI(), "NetworkTopic");

  ::IcmProxy::IcmMsg::Topic* topic = topicManager.retrieve("NetworkTopic");
  if(topic == 0)
	  topic = topicManager.create("NetworkTopic");
  if (topic == 0)
    return -1;
  topic->subscribe(networkProxy);

  comm->run();

  return 0;
}
Exemple #6
0
int main(int argc, char* argv[]) {
  struct sigaction sa;
  sigemptyset(&sa.sa_mask);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  sigaction( SIGPIPE, &sa, 0 );

  Communicator* comm = Communicator::instance();
  if (comm->init() == -1)
    return -1;

  //Reference ref(comm, Identity("MyHello"), Endpoint("TCP", "127.0.0.1", 3000));
  Reference ref(comm, Identity("MyHello"), Endpoint("TCP", "172.16.10.23", 3000), new TimeValue(3));
  IcmProxy::demo::MyHello myHello;
  myHello.setReference(&ref);

  Short u = 15;
  Long v;

  while(true) {

  ICC_DEBUG("sync calling.......");
  sleep(1);
  string ret = myHello.sayHello("Hello, sync1", u, v);
  if(ret == "") {
    cout << "call error!!" << endl;
  } else {
    cout << "call success!!" << endl;
    cout << "u:" << u << " v:" << v << " ret:" << ret << endl;
  }

  } // while

//  ICC_DEBUG("sync calling.......");
//  ret = myHello.sayHello("Hello, sync2", u, v);
//  cout << "u:" << u << " v:" << v << " ret:" << ret << endl;

//  ICC_DEBUG("async calling.......");
//  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async1", u);
//
//  ICC_DEBUG("async calling.......");
//  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async2", u);
//
//  ICC_DEBUG("async calling.......");
//  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async3", u);

//  static const char* __operation("sayHello");
//  TwowayAsynchInvocation _invocation (&ref, __operation, ref.communicator (), new AMI_MyHello_sayHelloI, ref.getMaxWaitTime());
//  IcmTransport * p = 0;
//  int ok = _invocation.start (p);
//  if (ok != 0)
//  {
//    IcmProxy::setCallErrno( ICM_INVOCATION_START_FAILED );
//    ICC_ERROR("invocation start ERROR!!!!!!");
//    return -1;
//  }
//  ok = _invocation.prepareHeader (1);
//  if (ok != 0)
//  {
//    IcmProxy::setCallErrno( ICM_INVOCATION_PREPAREHEADER_FAILED );
//    return -1;
//  }
//  OutputStream* __os = _invocation.outStream();
//  __os->write_string("Hello, asynctest");
//  __os->write_short(u);
////  ok = _invocation.invoke();
////  if(ok != 0)
////  {
////    IcmProxy::setCallErrno( ICM_INVOCATION_INVOKE_FAILED );
//////    this->transport(0);
////    ICC_ERROR("invocation start ERROR!!!!!!");
////    return -1;
////  }
//  int retval = _invocation.mTransport->tms()->bindDispatcher (_invocation.requestId(), _invocation.mRd);
//  if (retval == -1) {
////    this->closeConnection ();
//    return -1;
//  }
//  if(_invocation.mTransport->sendRequest(&ref,
//                                   comm,
//                                   *__os,
//                                   false,
//                                   0) == -1) {
//
//    return -1;
//  }


//  Rcver rcver(*comm, myHello);
//  rcver.activate();
//
//  comm->run();

//  while(true) {
//
//    ICC_DEBUG("async calling.......");
//    myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, sync1", u);
//    sleep(10);
//  } // while

  return 0;
}