Skip to content

Instantly share code, notes, and snippets.

@kandran
Last active November 2, 2018 17:49
Show Gist options
  • Save kandran/e9c67c33550596e61d27 to your computer and use it in GitHub Desktop.
Save kandran/e9c67c33550596e61d27 to your computer and use it in GitHub Desktop.
Corba is fun ! or not
#include <OB/CORBA.h>
#include "Calculator_impl.h"
//
// IDL:Calculator/memoire:1.0
//
::CORBA::Long Calculator_impl::memoire()
throw(::CORBA::SystemException){
return this-> _memoire;
}
void Calculator_impl::memoire(::CORBA::Long memoire )
throw(::CORBA::SystemException){
this->_memoire = memoire;
}
//
// IDL:Calculator/ajouter:1.0
//
::CORBA::Long Calculator_impl::ajouter(::CORBA::Long val)
throw(::CORBA::SystemException){
this->_memoire += val;
return this->_memoire;
}
//
// IDL:Calculator/soustraire:1.0
//
::CORBA::Long Calculator_impl::soustraire(::CORBA::Long val)
throw(::CORBA::SystemException){
this->_memoire -= val;
return this->_memoire;
}
//
// IDL:Calculator/multiplier:1.0
//
::CORBA::Long Calculator_impl::multiplier(::CORBA::Long val)
throw(::CORBA::SystemException){
this->_memoire *= val;
return this->_memoire;
}
//
// IDL:Calculator/diviser:1.0
//
::CORBA::Long Calculator_impl::diviser(::CORBA::Long val)
throw(::CORBA::SystemException){
this->_memoire /= val;
return this->_memoire;
}
#ifndef CALCULATOR_IMPL_H
#define CALCULATOR_IMPL_H
#include <calculator_skel.h>
class Calculator_impl : public POA_Calculator
{
public:
//
// IDL:Calculator/memoire:1.0
//
::CORBA::Long Calculator_impl::memoire()
throw(::CORBA::SystemException);
void Calculator_impl::memoire(::CORBA::Long)
throw(::CORBA::SystemException);
//
// IDL:Calculator/ajouter:1.0
//
::CORBA::Long Calculator_impl::ajouter(::CORBA::Long val)
throw(::CORBA::SystemException);
//
// IDL:Calculator/soustraire:1.0
//
::CORBA::Long Calculator_impl::soustraire(::CORBA::Long val)
throw(::CORBA::SystemException);
//
// IDL:Calculator/multiplier:1.0
//
::CORBA::Long Calculator_impl::multiplier(::CORBA::Long val)
throw(::CORBA::SystemException);
//
// IDL:Calculator/diviser:1.0
//
::CORBA::Long Calculator_impl::diviser(::CORBA::Long val)
throw(::CORBA::SystemException);
inline Calculator_impl::Calculator_impl()
{
this->_memoire = 0;
}
protected:
::CORBA::Long _memoire;
};
#endif
#include <iostream>
#include <string>
#include "OB/CORBA.h"
#include "OB/Cosnaming.h"
#include "calculator.h"
using namespace std;
int main(int argc, char** argv)
{
// Declare ORB
CORBA::ORB_var orb;
try {
// Initialize the ORB
orb = CORBA::ORB_init(argc, argv);
// Get a reference to the Naming Service
CORBA::Object_var rootContextObj =
orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var nc =
CosNaming::NamingContext::_narrow(rootContextObj.in());
CosNaming::Name name;
name.length(1);
name[0].id = (const char *) "calculatorService";
name[0].kind = (const char *) "";
// Invoke the root context to retrieve the object reference
CORBA::Object_var managerObj = nc->resolve(name);
// Narrow the previous object to obtain the correct type
::Calculator_var manager =
::Calculator::_narrow(managerObj.in());
manager->ajouter(5);
manager->soustraire(2);
manager->diviser(3);
manager->multiplier(10);
cout << manager->memoire() << endl;
}catch(const CORBA::Exception& e) {
// Handles CORBA exceptions
cerr << e << endl;
}
// End CORBA
if (!CORBA::is_nil(orb)){
try{
orb->destroy();
cout << "Ending CORBA..." << endl;
} catch(const CORBA::Exception& e)
{
cout << "orb->destroy failed:" << e << endl;
return 1;
}
}
return 0;
}
#include <OB/CORBA.h>
#include <OB/Cosnaming.h>
#include <stdlib.h>
#include <errno.h>
#ifdef HAVE_FSTREAM
# include <fstream>
#else
# include <fstream.h>
#endif
#include "Calculator_impl.h"
#ifdef HAVE_STD_IOSTREAM
using namespace std;
#endif
int main(int argc, char* argv[], char*[])
{
int status = EXIT_SUCCESS;
CORBA::ORB_var orb;
try
{
// Initialize the ORB.
orb = CORBA::ORB_init(argc, argv);
// Get a reference to the root POA
CORBA::Object_var rootPOAObj = orb->resolve_initial_references("RootPOA");
// Narrow it to the correct type
PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj.in());
// Get the POA manager object
PortableServer::POAManager_var manager = rootPOA->the_POAManager();
// Get a reference to the Naming Service root_context
CORBA::Object_var rootContextObj = orb->resolve_initial_references("NameService");
// Narrow to the correct type
CosNaming::NamingContext_var nc =CosNaming::NamingContext::_narrow(rootContextObj.in());
Calculator_impl* calculatorImpl = new Calculator_impl();
Calculator_var calculator = calculatorImpl -> _this();
CosNaming::Name name;
name.length(1);
name[0].id = (const char *) "calculatorService";
name[0].kind = (const char *) "";
// Bind the object into the name service
nc->rebind(name,calculator);
// Activate the POA
manager->activate();
std::cout << "Server ready. Waiting for requests..." << std::endl;
// Start the ORB
orb->run();
}
catch(const CORBA::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
// Sortie propre du programme.
if(!CORBA::is_nil(orb))
{
try
{
orb -> destroy();
}
catch(const CORBA::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
}
return status;
}
@chaslbiv
Copy link

chaslbiv commented Nov 2, 2018

Think you could leave the library you used (Calculator_impl) I would like to see which functions you have

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment