Commit be3ce2b4 authored by Ricardo Calheiros de Miranda Cosme's avatar Ricardo Calheiros de Miranda Cosme
Browse files

[OPENBUS-93]

+ Demo Hello Orbix
 - Uso explícito dos namespaces.
 - Pequenos ajustes nos arquivos .mak.
 - Scripts runserver e runclient que carregam o HOST e a PORTA do barramento no arquivo de configuração _democonfig_.
+ Lib Openbus Orbix
 - Argumentos de linha de comando OpenbusHost e OpenbusPort. O host e porta do barramento passam a ser armazenados
   internamente.
 - Especificação do tipo da exceção levantada por connect(). O _char*_ foi substituído pelas TAD's COMMUNICATION_FAILURE e LOGIN_FAILURE.
 


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@86242 ae0415b3-e90b-0410-900d-d0be9363c56b
parent c345abbe
......@@ -7,6 +7,8 @@
#include <omg/orb.hh>
#include <it_ts/thread.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
namespace openbus {
Openbus::RenewLeaseThread::RenewLeaseThread(Openbus* _bus) {
......@@ -35,6 +37,8 @@ namespace openbus {
credentialManager = new common::CredentialManager;
ini = new common::ORBInitializerImpl(credentialManager);
PortableInterceptor::register_orb_initializer(ini);
hostBus = (char*) "";
portBus = 2089;
}
Openbus::~Openbus() {
......@@ -61,6 +65,15 @@ namespace openbus {
poa_manager = poa->the_POAManager();
poa_manager->activate();
componentBuilder = new scs::core::ComponentBuilder(orb, poa);
for (short idx = 1; idx < argc; idx++) {
if (!strcmp(argv[idx], "-OpenbusHost")) {
idx++;
hostBus = argv[idx];
} else if (!strcmp(argv[idx], "-OpenbusPort")) {
idx++;
portBus = atoi(argv[idx]);
}
}
}
void Openbus::init(int argc, char** argv, CORBA::ORB* _orb, PortableServer::POA* _poa) {
......@@ -94,14 +107,29 @@ namespace openbus {
}
openbus::services::RegistryService* Openbus::connect(const char* host, unsigned short port, const char* user, \
const char* password)
const char* password) throw (COMMUNICATION_FAILURE, LOGIN_FAILURE)
{
#ifdef VERBOSE
cout << "[Openbus::connect() BEGIN]" << endl;
#endif
try {
#ifdef VERBOSE
cout << "\thost = "<< host << endl;
cout << "\tport = "<< port << endl;
cout << "\tuser = "<< user << endl;
cout << "\tpassword = "<< password << endl;
cout << "\torb = "<< orb << endl;
#endif
accessControlService = new openbus::services::AccessControlService(host, port, orb);
IAccessControlService* iAccessControlService = accessControlService->getStub();
#ifdef VERBOSE
cout << "\tiAccessControlService = "<< iAccessControlService << endl;
#endif
if (!iAccessControlService->loginByPassword(user, password, credential, lease)) {
throw "Par usuario/senha nao validado.";
throw LOGIN_FAILURE();
} else {
hostBus = (char*) host;
portBus = port;
credentialManager->setValue(credential);
timeRenewing = lease;
RenewLeaseThread* renewLeaseThread = new RenewLeaseThread(this);
......@@ -109,9 +137,18 @@ namespace openbus {
registryService = accessControlService->getRegistryService();
return registryService;
}
} catch (const char* errmsg) {
throw errmsg;
} catch (const CORBA::SystemException& systemException) {
throw COMMUNICATION_FAILURE();
}
#ifdef VERBOSE
cout << "[Openbus::connect() END]" << endl << endl;
#endif
}
openbus::services::RegistryService* Openbus::connect(const char* user, const char* password) \
throw (COMMUNICATION_FAILURE, LOGIN_FAILURE)
{
return connect(hostBus, portBus, user, password);
}
bool Openbus::logout() {
......
......@@ -20,6 +20,9 @@ using namespace openbusidl::acs;
IT_USING_NAMESPACE_STD
namespace openbus {
class COMMUNICATION_FAILURE {};
class LOGIN_FAILURE {};
class Openbus {
private:
static Openbus* instance;
......@@ -33,6 +36,8 @@ namespace openbus {
openbus::services::RegistryService* registryService;
Lease lease;
Credential* credential;
char* hostBus;
unsigned short portBus;
unsigned long timeRenewing;
IT_Thread renewLeaseIT_Thread;
Openbus();
......@@ -56,7 +61,9 @@ namespace openbus {
Credential* getCredential();
Lease getLease();
openbus::services::RegistryService* connect(const char* host, unsigned short port, const char* user, \
const char* password);
const char* password) throw (COMMUNICATION_FAILURE, LOGIN_FAILURE);
openbus::services::RegistryService* connect(const char* user, const char* password) \
throw (COMMUNICATION_FAILURE, LOGIN_FAILURE);
bool logout();
};
}
......
......@@ -4,12 +4,13 @@
#include "AccessControlService.h"
#include <omg/orb.hh>
#include <sstream>
namespace openbus {
namespace services {
AccessControlService::AccessControlService(const char* host, short unsigned int port, CORBA::ORB* _orb) {
AccessControlService::AccessControlService(const char* host, short unsigned int port, CORBA::ORB* _orb) \
throw (CORBA::SystemException)
{
std::stringstream corbaloc;
orb = _orb;
corbaloc << "corbaloc::" << host << ":" << port << "/ACS";
......
......@@ -5,8 +5,10 @@
#ifndef ACCESSCONTROLSERVICE_H_
#define ACCESSCONTROLSERVICE_H_
#include "RegistryService.h"
#include <omg/orb.hh>
#include "../stubs/access_control_service.hh"
#include "../stubs/registry_service.hh"
......@@ -17,7 +19,7 @@ namespace openbus {
CORBA::ORB* orb;
openbusidl::acs::IAccessControlService* iAccessControlService;
public:
AccessControlService(const char* host, short unsigned int port, CORBA::ORB* _orb);
AccessControlService(const char* host, short unsigned int port, CORBA::ORB* _orb) throw (CORBA::SystemException);
RegistryService* getRegistryService();
bool renewLease(openbusidl::acs::Credential credential, openbusidl::acs::Lease lease);
bool logout(openbusidl::acs::Credential credential);
......
......@@ -10,42 +10,43 @@
#include <openbus.h>
using namespace std;
using namespace openbusidl::acs;
using namespace openbusidl::rs;
using namespace openbus;
using namespace openbus::common;
int main(int argc, char* argv[]) {
Openbus* bus;
openbus::Openbus* bus;
openbus::services::RegistryService* registryService;
bus = Openbus::getInstance();
bus = openbus::Openbus::getInstance();
/* Criacao implicita do ORB. */
bus->init(argc, argv);
/* Conexao com o barramento. */
try {
registryService = bus->connect("localhost", 2089, "tester", "tester");
} catch (const char* errmsg) {
cout << "** Nao foi possivel se conectar ao barramento." << endl << errmsg << endl;
registryService = bus->connect("tester", "tester");
} catch (openbus::COMMUNICATION_FAILURE& e) {
cout << "** Nao foi possivel se conectar ao barramento. **" << endl \
<< "* Falha na comunicacao. *" << endl;
exit(-1);
} catch (openbus::LOGIN_FAILURE& e) {
cout << "** Nao foi possivel se conectar ao barramento. **" << endl \
<< "* Par usuario/senha invlido. *" << endl;
exit(-1);
}
CORBA::ULong idx = 0;
PropertyList_var p = new PropertyList(5);
openbusidl::rs::PropertyList_var p = new openbusidl::rs::PropertyList(5);
p->length(1);
ServiceOfferList_var soList = new ServiceOfferList(5);
openbusidl::rs::ServiceOfferList_var soList = new openbusidl::rs::ServiceOfferList(5);
soList->length(5);
Property_var property = new Property;
openbusidl::rs::Property_var property = new openbusidl::rs::Property;
property->name = "facet";
PropertyValue_var propertyValue = new PropertyValue(5);
openbusidl::rs::PropertyValue_var propertyValue = new openbusidl::rs::PropertyValue(5);
propertyValue->length(1);
propertyValue[0] = "IHello";
property->value = propertyValue;
p[0] = property;
soList = registryService->find(p);
ServiceOffer so;
openbusidl::rs::ServiceOffer so;
so = soList[idx];
scs::core::IComponent* component = so.member;
......
......@@ -9,7 +9,7 @@ EXTRA_CONFIG=config
CPPFLAGS= -g3 -mtune=pentium3 -march=i586 -pipe -D_REENTRANT -Wno-sign-compare
LFLAGS= $(CPPFLAGS) -rdynamic -L/usr/local/lib -Wl,-t -lpthread -lrt
CPPC=g++-3.4
CPPC=g++
DEFINES=${VERBOSE}
......@@ -21,8 +21,8 @@ LDIR= ${ORBIXLDIR}
LIBS= it_poa it_art it_ifc it_portable_interceptor
SLIB= ${OPENBUSLIB}/libscsorbix.a \
${OPENBUS_HOME}/core/utilities/orbix/lib/${TEC_UNAME}/libopenbus.a
SLIB= ${OPENBUS_HOME}/core/utilities/orbix/lib/${TEC_UNAME}/libopenbus.a \
${OPENBUSLIB}/libscsorbix.a
SRC= client.cpp helloC.cxx
......@@ -5,5 +5,3 @@ ORBIXBIN=${ORBIX_HOME}/bin
ORBIXINC=${ORBIX_HOME}/include
ORBIXLDIR=${ORBIX_HOME}/lib
#Descomente a linha abaixo para ativar o verbose.
#VERBOSE= VERBOSE
#Localizacao do barramento.
HOSTBUS='localhost'
PORTBUS='2089'
#!/bin/ksh
. ./democonfig
./client -OpenbusHost $HOSTBUS -OpenbusPort $PORTBUS
#!/bin/ksh
. ./democonfig
./server -OpenbusHost $HOSTBUS -OpenbusPort $PORTBUS
......@@ -13,14 +13,10 @@
#include "helloS.hh"
using namespace std;
using namespace openbusidl::acs;
using namespace openbusidl::rs;
using namespace openbus;
using namespace openbus::common;
IT_USING_NAMESPACE_STD
Openbus* bus;
openbus::Openbus* bus;
class Hello_impl : virtual public POA_Hello {
public:
......@@ -38,7 +34,7 @@ int main(int argc, char* argv[]) {
char* registryId;
openbus::services::RegistryService* registryService;
bus = Openbus::getInstance();
bus = openbus::Openbus::getInstance();
/* Se o usuario desejar criar o seu proprio ORB/POA.
bus->init(argc, argv, orb, root_poa);
......@@ -49,9 +45,14 @@ int main(int argc, char* argv[]) {
/* Conexao com o barramento. */
try {
registryService = bus->connect("localhost", 2089, "tester", "tester");
} catch (const char* errmsg) {
cout << "** Nao foi possivel se conectar ao barramento." << endl << errmsg << endl;
registryService = bus->connect("tester", "tester");
} catch (openbus::COMMUNICATION_FAILURE& e) {
cout << "** Nao foi possivel se conectar ao barramento. **" << endl \
<< "* Falha na comunicacao. *" << endl;
exit(-1);
} catch (openbus::LOGIN_FAILURE& e) {
cout << "** Nao foi possivel se conectar ao barramento. **" << endl \
<< "* Par usuario/senha invlido. *" << endl;
exit(-1);
}
......@@ -60,16 +61,16 @@ int main(int argc, char* argv[]) {
scs::core::ComponentBuilder* componentBuilder = bus->getComponentBuilder();
scs::core::IComponentImpl* IComponent = componentBuilder->createComponent("component", 1, "facet", "IDL:Hello:1.0", hello);
PropertyList_var p = new PropertyList(5);
openbusidl::rs::PropertyList_var p = new openbusidl::rs::PropertyList(5);
p->length(1);
Property_var property = new Property;
openbusidl::rs::Property_var property = new openbusidl::rs::Property;
property->name = "facet";
PropertyValue_var propertyValue = new PropertyValue(5);
openbusidl::rs::PropertyValue_var propertyValue = new openbusidl::rs::PropertyValue(5);
propertyValue->length(1);
propertyValue[0] = "IHello";
property->value = propertyValue;
p[0] = property;
ServiceOffer so;
openbusidl::rs::ServiceOffer so;
so.properties = p;
so.member = IComponent->_this();
......
......@@ -9,7 +9,7 @@ EXTRA_CONFIG=config
CPPFLAGS= -g3 -mtune=pentium3 -march=i586 -pipe -D_REENTRANT -Wno-sign-compare
LFLAGS= $(CPPFLAGS) -rdynamic -L/usr/local/lib -Wl,-t -lpthread -lrt
CPPC=g++-3.4
CPPC=g++
DEFINES=${VERBOSE}
......
......@@ -48,7 +48,7 @@ namespace scs {
facet->name = name;
facet->interface_name = interface_name;
facet->facet_ref = ref;
facets[ name ] = *facet;
facets[name] = *facet;
#ifdef VERBOSE
CORBA::String_var str = _orb->object_to_string(ref.in());
cout << "\t[IOR:]" << str.in() << endl;
......@@ -71,9 +71,9 @@ namespace scs {
#endif
CORBA::Object_var o = new CORBA::Object();
FacetDescription* f = NULL;
for(it = facets.begin(); it != facets.end(); it++) {
for (it = facets.begin(); it != facets.end(); it++) {
f = &(*it).second;
if(strcmp(f->interface_name, facet_interface) == 0) {
if (strcmp(f->interface_name, facet_interface) == 0) {
#ifdef VERBOSE
cout << "\t[Faceta de interface '" << facet_interface << "' encontrada]" << endl;
#endif
......@@ -92,15 +92,15 @@ namespace scs {
cout << "\n\n[IComponentImpl::getFacetByName() BEGIN]" << endl;
#endif
FacetDescription f;
if(facets.find(facet) == facets.end()) {
if (facets.find(facet) == facets.end()) {
#ifdef VERBOSE
cout << "\t[Faceta de nome '" << facet << "' encontrada]" << endl;
cout << "[IComponentImpl::getFacetByName() END]" << endl;
#endif
return facets[ facet ].facet_ref;
return facets[facet].facet_ref;
}
#ifdef VERBOSE
cout << "\t[Faceta de nome '" << facet << "' No encontrada]" << endl;
cout << "\t[Faceta de nome '" << facet << "' no encontrada]" << endl;
cout << "[IComponentImpl::getFacetByName() END]" << endl;
#endif
return NULL;
......
......@@ -100,7 +100,7 @@ namespace scs {
return facets[facet].facet_ref;
}
#ifdef VERBOSE
cout << "\t[Faceta de nome '" << facet << "' N�O encontrada]" << endl;
cout << "\t[Faceta de nome '" << facet << "' no encontrada]" << endl;
cout << "[IComponentImpl::getFacetByName() END]" << endl;
#endif
return NULL;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment