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

[OPENBUS-90]

+ Refatoramento lib CPPOIL
 - Ocultação do mecanismo de interceptação.
 - Simplificação do procedimento de conexão/login por usuário/senha.



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@84574 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 55758d5a
......@@ -13,11 +13,16 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
using namespace std;
namespace openbus {
lua_State* Openbus::LuaVM = 0;
Openbus* Openbus::instance = 0;
common::CredentialManager* Openbus::credentialManager = 0;
common::ClientInterceptor* Openbus::clientInterceptor = 0;
Lua_State* Openbus::getLuaVM(void) {
return LuaVM;
......@@ -55,11 +60,16 @@ namespace openbus {
Openbus::~Openbus() {
instance = 0;
delete clientInterceptor;
delete credentialManager;
}
Openbus* Openbus::getInstance() {
if (instance == 0) {
instance = new Openbus;
credentialManager = new common::CredentialManager();
clientInterceptor = new common::ClientInterceptor(credentialManager);
instance->setClientInterceptor(clientInterceptor);
}
return instance;
}
......@@ -115,8 +125,21 @@ namespace openbus {
#endif
}
services::IAccessControlService* Openbus::getACS(String reference, String interface) {
return new services::IAccessControlService(reference, interface);
services::IAccessControlService* Openbus::getACS(String host, unsigned short port) {
stringstream corbaloc;
corbaloc << "corbaloc::" << host << ":" << port << "/ACS";
return new services::IAccessControlService(corbaloc.str().c_str(), "IDL:openbusidl/acs/IAccessControlService:1.0");
}
services::IAccessControlService* Openbus::connect(String host, unsigned short port, String user, String password, \
services::Credential* aCredential, services::Lease* aLease) {
services::IAccessControlService* acs = getACS(host, port);
if (!acs->loginByPassword(user, password, aCredential, aLease)) {
return 0;
} else {
credentialManager->setValue(aCredential);
return acs;
}
}
}
......@@ -22,6 +22,7 @@ namespace openbus {
struct Credential;
struct ServiceOffer;
typedef Identifier RegistryIdentifier;
typedef Long Lease;
class ICredentialObserver;
class IAccessControlService;
class IRegistryService;
......@@ -46,6 +47,8 @@ namespace openbus {
private:
static Openbus* instance;
static Lua_State* LuaVM;
static common::CredentialManager* credentialManager;
static common::ClientInterceptor* clientInterceptor;
void initLuaVM();
Openbus();
Openbus(const Openbus&);
......@@ -54,7 +57,9 @@ namespace openbus {
static Openbus* getInstance();
Lua_State* getLuaVM();
void setClientInterceptor(common::ClientInterceptor* clientInterceptor);
services::IAccessControlService* getACS(String reference, String interface);
services::IAccessControlService* getACS(String host, unsigned short port);
services::IAccessControlService* connect(String host, unsigned short port, String user, String password, \
services::Credential* aCredential, services::Lease* aLease);
};
}
......
......@@ -9,7 +9,7 @@
#define USER "tester" /* Usuario OpenBus. */
#define PASSWORD "tester" /* Senha do usuario OpenBus. */
#define HOST "localhost" /* Host onde esta o servico de controle de acesso. */
#define PORT "2089" /* Porta do servico de controle de acesso. */
#define PORT 2089 /* Porta do servico de controle de acesso. */
/**************************************************************************************************/
......@@ -36,18 +36,13 @@ int main(int argc, char** argv) {
Openbus* openbus = Openbus::getInstance();
common::CredentialManager* credentialManager = new common::CredentialManager();
common::ClientInterceptor* clientInterceptor = new common::ClientInterceptor(credentialManager);
openbus->setClientInterceptor(clientInterceptor);
stringstream corbaloc;
corbaloc << "corbaloc::" << HOST << ":" << PORT << "/ACS";
services::IAccessControlService* acs = openbus->getACS(corbaloc.str().c_str(), "IDL:openbusidl/acs/IAccessControlService:1.0");
/* Autenticacao no barramento. */
/* Conexao com o barramento. */
services::Credential* credential = new services::Credential();
services::Lease* lease = new services::Lease();
services::IAccessControlService* acs;
try {
if (!acs->loginByPassword(USER, PASSWORD, credential, lease)) {
acs = openbus->connect(HOST, (unsigned short) PORT, USER, PASSWORD, credential, lease);
if (!acs) {
throw "Servico de controle de acesso localizado, porem o par usuario/senha nao foi validado.";
}
} catch (const char* errmsg) {
......@@ -55,8 +50,6 @@ int main(int argc, char** argv) {
exit(-1);
}
credentialManager->setValue(credential);
services::IRegistryService* rgs = acs->getRegistryService();
services::PropertyList* propertyList = new services::PropertyList;
services::Property* property = new services::Property;
......
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