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

[OPENBUS-93]

+ Wrapper para o serviço de acesso e de registro.
+ Método init() que cria um ORB implicitamente.
+ O método Openbus::connect() passa a retornar um ponteiro para o wrapper do serviço de registro, ao invés de retornar um
ponteiro para o wrapper do serviço de acesso.
+ Implementação de um mecanismo de renovação de credencial baseado na API de manipulação de threads do Orbix.
+ Método Openbus::logout().
+ Classe *ComponentBuilder* responsável pela criação de componentes.



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@85901 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 6048c372
......@@ -14,7 +14,7 @@ DEFINES=VERBOSE
OBJROOT= obj
TARGETROOT= lib
INCLUDES= . ${ORBIXINC}
INCLUDES= . ${ORBIXINC} ${OPENBUSINC}/scs
LDIR= ${ORBIXLDIR} ${OPENBUSLIB}
LIBS= it_poa it_art it_ifc it_portable_interceptor scsorbix
......@@ -27,7 +27,10 @@ SRC= openbus/common/ClientInterceptor.cpp \
stubs/registry_serviceC.cxx \
stubs/session_serviceC.cxx \
stubs/coreC.cxx \
stubs/scsC.cxx
stubs/scsC.cxx \
services/AccessControlService.cpp \
services/RegistryService.cpp \
openbus.cpp
genstubs:
mkdir -p stubs
......
/*
** openbus.cpp
*/
#include "openbus.h"
#include <omg/orb.hh>
#include <it_ts/thread.h>
#include <sstream>
namespace openbus {
Openbus::RenewLeaseThread::RenewLeaseThread(Openbus* _bus) {
bus = _bus;
}
void* Openbus::RenewLeaseThread::run() {
unsigned long time;
while (true) {
time = ((bus->timeRenewing)/2)*1000;
IT_CurrentThread::sleep(time);
bus->accessControlService->renewLease(*bus->credential, bus->lease);
}
return 0;
}
Openbus* Openbus::instance = 0;
common::CredentialManager* Openbus::credentialManager = 0;
common::ORBInitializerImpl* Openbus::ini = 0;
CORBA::ORB* Openbus::orb = CORBA::ORB::_nil();
PortableServer::POA* Openbus::poa = 0;
scs::core::ComponentBuilder* Openbus::componentBuilder = 0;
PortableServer::POAManager_var Openbus::poa_manager = 0;
Openbus::Openbus() {
credentialManager = new common::CredentialManager;
ini = new common::ORBInitializerImpl(credentialManager);
PortableInterceptor::register_orb_initializer(ini);
}
Openbus::~Openbus() {
delete credentialManager;
delete ini;
delete componentBuilder;
}
Openbus* Openbus::getInstance() {
if (instance == 0) {
instance = new Openbus;
}
return instance;
}
void Openbus::run() {
orb->run();
}
void Openbus::init(int argc, char** argv) {
orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
poa = PortableServer::POA::_narrow(poa_obj);
poa_manager = poa->the_POAManager();
poa_manager->activate();
componentBuilder = new scs::core::ComponentBuilder(orb, poa);
}
void Openbus::init(int argc, char** argv, CORBA::ORB* _orb, PortableServer::POA* _poa) {
orb = _orb;
poa = _poa;
componentBuilder = new scs::core::ComponentBuilder(orb, poa);
}
scs::core::ComponentBuilder* Openbus::getComponentBuilder() {
return componentBuilder;
}
common::ServerInterceptor* Openbus::getServerInterceptor() {
return ini->getServerInterceptor();
}
common::CredentialManager* Openbus::getCredentialManager() {
return credentialManager;
}
openbus::services::AccessControlService* Openbus::getAccessControlService() {
return accessControlService;
}
Credential* Openbus::getCredential() {
return credential;
}
Lease Openbus::getLease() {
return lease;
}
openbus::services::RegistryService* Openbus::connect(const char* host, unsigned short port, const char* user, \
const char* password)
{
try {
accessControlService = new openbus::services::AccessControlService(host, port, orb);
IAccessControlService* iAccessControlService = accessControlService->getStub();
if (!iAccessControlService->loginByPassword(user, password, credential, lease)) {
throw "Par usuario/senha nao validado.";
} else {
credentialManager->setValue(credential);
timeRenewing = lease;
RenewLeaseThread* renewLeaseThread = new RenewLeaseThread(this);
renewLeaseIT_Thread = IT_ThreadFactory::smf_start(*renewLeaseThread, IT_ThreadFactory::attached, 0);
registryService = accessControlService->getRegistryService();
return registryService;
}
} catch (const char* errmsg) {
throw errmsg;
}
}
bool Openbus::logout() {
return accessControlService->logout(*credential);
}
}
......@@ -5,11 +5,60 @@
#ifndef OPENBUS_H_
#define OPENBUS_H_
#include "services/AccessControlService.h"
#include "stubs/access_control_service.hh"
#include "openbus/common/CredentialManager.h"
#include "openbus/common/ORBInitializerImpl.h"
#include "openbus/common/ServerInterceptor.h"
#include <scs/core/IComponentOrbix.h>
#include <scs/core/ComponentBuilder.h>
#endif
#include <omg/orb.hh>
#include <it_ts/thread.h>
using namespace openbusidl::acs;
IT_USING_NAMESPACE_STD
namespace openbus {
class Openbus {
private:
static Openbus* instance;
static common::CredentialManager* credentialManager;
static common::ORBInitializerImpl* ini;
static CORBA::ORB* orb;
static PortableServer::POA* poa;
static scs::core::ComponentBuilder* componentBuilder;
static PortableServer::POAManager_var poa_manager;
openbus::services::AccessControlService* accessControlService;
openbus::services::RegistryService* registryService;
Lease lease;
Credential* credential;
unsigned long timeRenewing;
IT_Thread renewLeaseIT_Thread;
Openbus();
class RenewLeaseThread : public IT_ThreadBody {
private:
Openbus* bus;
public:
RenewLeaseThread(Openbus* _bus);
void* run();
};
public:
~Openbus();
static Openbus* getInstance();
void run();
void init(int argc, char** argv);
void init(int argc, char** argv, CORBA::ORB_ptr _orb, PortableServer::POA* _poa);
scs::core::ComponentBuilder* getComponentBuilder();
common::ServerInterceptor* getServerInterceptor();
common::CredentialManager* getCredentialManager();
openbus::services::AccessControlService* getAccessControlService();
Credential* getCredential();
Lease getLease();
openbus::services::RegistryService* connect(const char* host, unsigned short port, const char* user, \
const char* password);
bool logout();
};
}
#endif
/*
** AccessControlService.cpp
*/
#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) {
std::stringstream corbaloc;
orb = _orb;
corbaloc << "corbaloc::" << host << ":" << port << "/ACS";
CORBA::Object_var obj = orb->string_to_object(corbaloc.str().c_str());
iAccessControlService = openbusidl::acs::IAccessControlService::_narrow(obj);
}
RegistryService* AccessControlService::getRegistryService() {
return new RegistryService(iAccessControlService->getRegistryService());
}
bool AccessControlService::renewLease(openbusidl::acs::Credential credential, openbusidl::acs::Lease lease) {
return iAccessControlService->renewLease(credential, lease);
}
bool AccessControlService::logout(openbusidl::acs::Credential credential) {
return iAccessControlService->logout(credential);
}
openbusidl::acs::IAccessControlService* AccessControlService::getStub() {
return iAccessControlService;
}
}
}
/*
** AccessControlService.h
*/
#ifndef ACCESSCONTROLSERVICE_H_
#define ACCESSCONTROLSERVICE_H_
#include "RegistryService.h"
#include "../stubs/access_control_service.hh"
#include "../stubs/registry_service.hh"
namespace openbus {
namespace services {
class AccessControlService {
private:
CORBA::ORB* orb;
openbusidl::acs::IAccessControlService* iAccessControlService;
public:
AccessControlService(const char* host, short unsigned int port, CORBA::ORB* _orb);
RegistryService* getRegistryService();
bool renewLease(openbusidl::acs::Credential credential, openbusidl::acs::Lease lease);
bool logout(openbusidl::acs::Credential credential);
openbusidl::acs::IAccessControlService* getStub();
};
}
}
#endif
/*
** RegistryService.cpp
*/
#include "RegistryService.h"
#define VECTORSIZE 256
namespace openbus {
namespace services {
RegistryService::RegistryService(openbusidl::rs::IRegistryService* _rgs) {
rgs = _rgs;
}
openbusidl::rs::ServiceOfferList* RegistryService::find(openbusidl::rs::PropertyList criteria) {
return rgs->find(criteria);
}
void RegistryService::Register(openbusidl::rs::ServiceOffer serviceOffer, char* registryId) {
rgs->_cxx_register(serviceOffer, registryId);
}
void RegistryService::Register(PropertyList propertyList, scs::core::IComponent* iComponent, char* registryId) {
/* char* propertyList[3] = {"facet", "IHello", 0};
registryService->Register(propertyList, IComponent->_this(), registryId);*/
openbusidl::rs::ServiceOffer serviceOffer;
openbusidl::rs::PropertyList_var pList = new openbusidl::rs::PropertyList(VECTORSIZE);
pList->length(1);
CORBA::ULong idx;
for (idx = 0;propertyList[idx] != 0;) {
std::cout << idx << std::endl << std::endl << std::endl;
openbusidl::rs::Property_var property = new openbusidl::rs::Property;
property->name = propertyList[idx];
openbusidl::rs::PropertyValue_var propertyValue = new openbusidl::rs::PropertyValue(VECTORSIZE);
propertyValue->length(1);
propertyValue[0] = propertyList[idx+1];
property->value = propertyValue;
pList[idx] = property;
idx++;
idx++;
}
serviceOffer.member = iComponent;
serviceOffer.properties = pList;
rgs->_cxx_register(serviceOffer, registryId);
}
}
}
/*
** RegistryService.h
*/
#ifndef REGISTRYSERVICE_H_
#define REGISTRYSERVICE_H_
#include "../stubs/scs.hh"
#include "../stubs/registry_service.hh"
namespace openbus {
namespace services {
typedef char** PropertyList;
class RegistryService {
private:
openbusidl::rs::IRegistryService* rgs;
public:
RegistryService(openbusidl::rs::IRegistryService* _rgs);
openbusidl::rs::ServiceOfferList* find(openbusidl::rs::PropertyList criteria);
void Register(openbusidl::rs::ServiceOffer serviceOffer, char* registryId);
void Register(PropertyList propertyList, scs::core::IComponent* iComponent, char* registryId);
};
}
}
#endif
......@@ -12,62 +12,48 @@
using namespace std;
using namespace openbusidl::acs;
using namespace openbusidl::rs;
using namespace openbus;
using namespace openbus::common;
int main(int argc, char* argv[]) {
Lease lease = 0;
Credential_var credential;
CredentialManager credentialManager;
Openbus* bus;
openbus::services::RegistryService* registryService;
ORBInitializerImpl* ini = new ORBInitializerImpl(&credentialManager);
PortableInterceptor::register_orb_initializer(ini);
bus = Openbus::getInstance();
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj);
PortableServer::POAManager_var mgr = poa->the_POAManager();
/* Criacao implicita do ORB. */
bus->init(argc, argv);
CORBA::Object_var obj = orb->string_to_object("corbaloc::localhost:2089/ACS");
IAccessControlService_var acs = IAccessControlService::_narrow(obj);
bool status = acs->loginByPassword("tester", "tester", credential, lease);
if (status) {
credentialManager.setValue(credential);
cout << endl << "CLIENT" << endl;
cout << "Login efetuado no Openbus." << endl;
cout << "owner = " << credential->owner.in() << endl;
cout << "identifier = " << credential->identifier.in() << endl;
} else {
return -1;
/* 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;
exit(-1);
}
CORBA::ULong idx = 0;
IRegistryService_var rgs = acs->getRegistryService();
PropertyList_var p = new PropertyList(5);
p->length(1);
ServiceOfferList_var soList = new ServiceOfferList(5);
soList->length(5);
Property_var property = new Property;
property->name = "type";
property->name = "facet";
PropertyValue_var propertyValue = new PropertyValue(5);
propertyValue->length(1);
propertyValue[0] = "type1";
propertyValue[0] = "IHello";
property->value = propertyValue;
p[0] = property;
soList = rgs->find(p);
soList = registryService->find(p);
ServiceOffer so;
so = soList[ idx ];
::scs::core::IComponent_var member;
member = so.member;
obj = member->getFacet("IDL:Hello:1.0");
/*test*/
/* printf("%p", member->getFacetByName("facet"));
printf("%p", member->getFacetByName("facet2"));
::scs::core::ComponentId* cId = member->getComponentId();
printf("%s %lu", cId->name.in(), cId->version);*/
/**/
Hello_var hello = Hello::_narrow(obj);
so = soList[idx];
scs::core::IComponent* component = so.member;
CORBA::Object* obj = component->getFacet("IDL:Hello:1.0");
Hello* hello = Hello::_narrow(obj);
hello->sayHello();
CORBA::release(orb);
bus->logout();
return 0;
}
......@@ -6,6 +6,7 @@
#include <fstream>
#include <iostream>
#include <omg/orb.hh>
#include <it_ts/thread.h>
#include <openbus.h>
......@@ -14,78 +15,68 @@
using namespace std;
using namespace openbusidl::acs;
using namespace openbusidl::rs;
using namespace openbus;
using namespace openbus::common;
IT_USING_NAMESPACE_STD
char* id;
IRegistryService_var rgs;
ORBInitializerImpl* ini;
openbus::common::ServerInterceptor* serverInterceptor;
Openbus* bus;
class Hello_impl : virtual public POA_Hello {
public:
void sayHello() IT_THROW_DECL((CORBA::SystemException)) {
cout << endl << "Servant diz: HELLO!" << endl;
serverInterceptor = ini->getServerInterceptor();
openbusidl::acs::Credential_var c = serverInterceptor->getCredential();
cout << "Usurio OpenBus que fez a chamada: " << c->owner.in() << endl;
openbus::common::ServerInterceptor* serverInterceptor = bus->getServerInterceptor();
openbusidl::acs::Credential_var credential = serverInterceptor->getCredential();
cout << "Usurio OpenBus que fez a chamada: " << credential->owner.in() << endl;
};
};
CORBA::ORB_ptr orb = CORBA::ORB::_nil();
Hello_impl* hello;
PortableServer::POA_var root_poa;
int main(int argc, char* argv[]) {
Lease lease = 0;
Credential_var credential;
openbus::common::CredentialManager credentialManager;
ini = new ORBInitializerImpl(&credentialManager);
PortableInterceptor::register_orb_initializer(ini);
orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
root_poa = PortableServer::POA::_narrow(poa_obj);
PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
CORBA::Object_var obj = orb->string_to_object("corbaloc::localhost:2089/ACS");
IAccessControlService_var acs = IAccessControlService::_narrow(obj);
bool status = acs->loginByPassword("tester", "tester", credential, lease);
if (status) {
credentialManager.setValue(credential);
cout << "SERVER" << endl;
cout << "Login efetuado no Openbus." << endl;
cout << "owner = " << credential->owner.in() << endl;
cout << "identifier = " << credential->identifier.in() << endl;
} else {
return -1;
char* registryId;
openbus::services::RegistryService* registryService;
bus = Openbus::getInstance();
/* Se o usuario desejar criar o seu proprio ORB/POA.
bus->init(argc, argv, orb, root_poa);
*/
/* 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;
exit(-1);
}
rgs = acs->getRegistryService();
hello = new Hello_impl;
scs::core::IComponentImpl* c = new scs::core::IComponentImpl("component", 1, orb, root_poa);
scs::core::ComponentBuilder* componentBuilder = bus->getComponentBuilder();
scs::core::IComponentImpl* IComponent = componentBuilder->createComponent("component", 1, "facet", "IDL:Hello:1.0", hello);
c->addFacet("facet", "IDL:Hello:1.0", hello);
poa_manager->activate();
PropertyList_var p = new PropertyList(5);
p->length(1);
Property_var property = new Property;
property->name = "type";
property->name = "facet";
PropertyValue_var propertyValue = new PropertyValue(5);
propertyValue->length(1);
propertyValue[0] = "type1";
propertyValue[0] = "IHello";
property->value = propertyValue;
p[0] = property;
ServiceOffer so;
so.properties = p;
so.member = c->_this();
rgs->_cxx_register(so, id);
so.member = IComponent->_this();
registryService->Register(so, registryId);
cout << "Servio HELLO registrado no OpenBus..." << endl;
orb->run();
bus->run();
return 0;
}
/*
** ComponentBuilder.h
*/
#ifndef COMPONENTBUILDER_H_
#define COMPONENTBUILDER_H_
#include "IComponentOrbix.h"
namespace scs {
namespace core {
class ComponentBuilder {
private:
CORBA::ORB* orb;
PortableServer::POA* poa;
public:
ComponentBuilder(CORBA::ORB* _orb, PortableServer::POA* _poa);
~ComponentBuilder();
IComponentImpl* createComponent(const char* name, unsigned long version, const char* facet_name, \
const char* interface_name, PortableServer::ServantBase* obj);
};
}
}
#endif
/*
** ComponentBuilder.cpp
*/
#include <scs/core/ComponentBuilder.h>
namespace scs {
namespace core {
ComponentBuilder::ComponentBuilder(CORBA::ORB* _orb, PortableServer::POA* _poa) {
orb = _orb;
poa = _poa;
}