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

[OPENBUS-90]

+ Método init().
+ Classe *ComponentBuilder*.



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@85903 ae0415b3-e90b-0410-900d-d0be9363c56b
parent d66d0985
......@@ -24,6 +24,7 @@ namespace openbus {
common::CredentialManager* Openbus::credentialManager = 0;
common::ClientInterceptor* Openbus::clientInterceptor = 0;
common::ServerInterceptor* Openbus::serverInterceptor = 0;
scs::core::ComponentBuilder* Openbus::componentBuilder = 0;
Lua_State* Openbus::getLuaVM(void) {
return LuaVM;
......@@ -105,6 +106,15 @@ namespace openbus {
}
}
void Openbus::init(int argc, char** argv) {
componentBuilder = new scs::core::ComponentBuilder();
componentBuilder->setLuaVM(LuaVM);
}
scs::core::ComponentBuilder* Openbus::getComponentBuilder() {
return componentBuilder;
}
void Openbus::setClientInterceptor(common::ClientInterceptor* clientInterceptor) {
#if VERBOSE
cout << "[Openbus::setClientInterceptor() COMECO]" << endl;
......
......@@ -7,7 +7,7 @@
#include "luaidl/cpp/types.h"
#include <scs/core/IComponentOil.h>
#include <scs/core/ComponentBuilderOil.h>
typedef struct lua_State Lua_State;
......@@ -51,6 +51,7 @@ namespace openbus {
static common::CredentialManager* credentialManager;
static common::ClientInterceptor* clientInterceptor;
static common::ServerInterceptor* serverInterceptor;
static scs::core::ComponentBuilder* componentBuilder;
void initLuaVM();
Openbus();
Openbus(const Openbus&);
......@@ -58,6 +59,8 @@ namespace openbus {
~Openbus();
static Openbus* getInstance();
void run();
void init(int argc, char** argv);
scs::core::ComponentBuilder* getComponentBuilder();
Lua_State* getLuaVM();
common::ServerInterceptor* getServerInterceptor();
void setClientInterceptor(common::ClientInterceptor* clientInterceptor);
......
/*
** Demo Hello
** Demo Hello - OiL
** client.cpp
*/
......@@ -12,21 +12,24 @@ using namespace openbus;
using namespace std;
int main(int argc, char** argv) {
Openbus* openbus = Openbus::getInstance();
services::IAccessControlService* accessControlService;
services::IRegistryService* registryService;
Openbus* bus = Openbus::getInstance();
bus->init(argc, argv);
/* Conexao com o barramento. */
services::Credential* credential = new services::Credential();
services::Lease* lease = new services::Lease();
services::IAccessControlService* acs;
try {
acs = openbus->connect("localhost", 2089, "tester", "tester", credential, lease);
accessControlService = bus->connect("localhost", 2089, "tester", "tester", credential, lease);
} catch (const char* errmsg) {
cout << "** Nao foi possivel se conectar ao barramento." << endl << errmsg << endl;
exit(-1);
}
/* Adquirindo o servico de registro. */
services::IRegistryService* rgs = acs->getRegistryService();
registryService = accessControlService->getRegistryService();
/* Procurando o servico hello. */
services::PropertyList* propertyList = new services::PropertyList;
......@@ -35,7 +38,7 @@ int main(int argc, char** argv) {
property->value = new services::PropertyValue;
property->value->newmember("IHello");
propertyList->newmember(property);
services::ServiceOfferList* serviceOfferList = rgs->find(propertyList);
services::ServiceOfferList* serviceOfferList = registryService->find(propertyList);
if (!serviceOfferList) {
cout << "** Nenhum servico hello foi encontrado no barramento." << endl;
exit(-1);
......@@ -50,4 +53,4 @@ int main(int argc, char** argv) {
hello->sayHello();
return 0;
}
\ No newline at end of file
}
/*
** Demo Hello
** Demo Hello - OiL
** server.cpp
*/
......@@ -13,28 +13,31 @@ using namespace openbus;
using namespace std;
int main(int argc, char** argv) {
Openbus* openbus = Openbus::getInstance();
services::IAccessControlService* accessControlService;
services::IRegistryService* registryService;
Openbus* bus = Openbus::getInstance();
bus->init(argc, argv);
/* Conexao com o barramento. */
services::Credential* credential = new services::Credential();
services::Lease* lease = new services::Lease();
services::IAccessControlService* acs;
try {
acs = openbus->connect("localhost", 2089, "tester", "tester", credential, lease);
accessControlService = bus->connect("localhost", 2089, "tester", "tester", credential, lease);
} catch (const char* errmsg) {
cout << "** Nao foi possivel se conectar ao barramento." << endl << errmsg << endl;
exit(-1);
}
/* Adquirindo o servico de registro. */
services::IRegistryService* rgs = acs->getRegistryService();
registryService = accessControlService->getRegistryService();
/* Criando um componente que disponibiliza uma faceta do servico hello. */
scs::core::IComponent* member = new scs::core::IComponent();
member->loadidlfile("../idl/hello.idl");
tolua_hello_open(openbus->getLuaVM());
tolua_hello_open(bus->getLuaVM());
IHello* hello = new IHello;
member->addFacet("hello", "IDL:demoidl/hello/IHello:1.0", "IHello", hello);
scs::core::ComponentBuilder* componentBuilder = bus->getComponentBuilder();
componentBuilder->loadIDLFile("../idl/hello.idl");
scs::core::IComponent* iComponent = componentBuilder->createComponent("component", 1, "facet", "IDL:demoidl/hello/IHello:1.0", "IHello", hello);
/* Registrando no barramento o servico hello. */
services::PropertyList* propertyList = new services::PropertyList;
......@@ -46,12 +49,12 @@ int main(int argc, char** argv) {
propertyList->newmember(property);
services::ServiceOffer* serviceOffer = new services::ServiceOffer;
serviceOffer->properties = propertyList;
serviceOffer->member = member;
serviceOffer->member = iComponent;
char* RegistryIdentifier;
rgs->Register(serviceOffer, RegistryIdentifier);
registryService->Register(serviceOffer, RegistryIdentifier);
/* O processo fica no aguardo de requisies CORBA referentes ao servico hello. */
openbus->run();
bus->run();
return 0;
}
/*
** ComponentBuilderOil.h
*/
#ifndef COMPONENTBUILDEROIL_H_
#define COMPONENTBUILDEROIL_H_
#include "IComponentOil.h"
namespace scs {
namespace core {
class ComponentBuilder {
private:
static lua_State* LuaVM;
public:
ComponentBuilder();
~ComponentBuilder();
void setLuaVM(lua_State* L);
IComponent* createComponent(const char* name, unsigned long version, const char* facet_name, \
const char* interface_name, char* constructor_name, void* obj);
void loadIDLFile(const char* idlfilename);
};
}
}
#endif
......@@ -27,10 +27,10 @@ namespace scs {
~IComponent();
static void setLuaVM(lua_State* L);
void addFacet (const char* name, const char* interface_name, void * facet_servant);
void addFacet (const char* name, const char* interface_name, void* facet_servant);
/* ToLua Support */
void addFacet (const char* name, const char* interface_name, \
char* constructor_name, void * facet_servant);
char* constructor_name, void* facet_servant);
void loadidl(const char* idl);
void loadidlfile(const char* idlfilename);
template <class T>
......@@ -41,8 +41,6 @@ namespace scs {
return (T*) ptr;
}
ComponentId* getComponentId();
// friend class openbus::services::IRegistryService;
};
typedef luaidl::cpp::sequence<IComponent> IComponentSeq;
......
/*
** ComponentBuilderOil.cpp
*/
#include <scs/core/ComponentBuilderOil.h>
#include <lua.hpp>
namespace scs {
namespace core {
lua_State* ComponentBuilder::LuaVM = 0;
ComponentBuilder::ComponentBuilder() {
/* empty */
}
ComponentBuilder::~ComponentBuilder() {
/* empty */
}
void ComponentBuilder::setLuaVM(lua_State* L) {
LuaVM = L;
}
IComponent* ComponentBuilder::createComponent(const char* name, unsigned long version, const char* facet_name, \
const char* interface_name, char* constructor_name, void* obj)
{
IComponent* iComponent = new IComponent(name);
iComponent->addFacet(facet_name, interface_name, constructor_name, obj);
return iComponent;
}
void ComponentBuilder::loadIDLFile(const char* idlfilename)
{
#if VERBOSE
printf("[ComponentBuilder::loadIDLFile() COMECO]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("\t[Carregando proxy para IComponent]\n");
#endif
lua_getglobal(LuaVM, "orb");
lua_getfield(LuaVM, -1, "loadidlfile");
lua_insert(LuaVM, -2);
#if VERBOSE
printf("\t[metodo loadidlfile empilhado]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
#endif
lua_pushstring(LuaVM, idlfilename);
#if VERBOSE
printf("\t[idlfilename=%s empilhado]\n", idlfilename);
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
#endif
if (lua_pcall(LuaVM, 2, 0, 0) != 0) {
#if VERBOSE
printf("\t[ERRO ao realizar pcall do metodo]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("\t[Tipo do elemento do TOPO: %s]\n" , \
lua_typename(LuaVM, lua_type(LuaVM, -1)));
#endif
const char * returnValue;
lua_getglobal(LuaVM, "tostring");
lua_insert(LuaVM, -2);
lua_pcall(LuaVM, 1, 1, 0);
returnValue = lua_tostring(LuaVM, -1);
lua_pop(LuaVM, 1);
#if VERBOSE
printf("\t[lancando excecao %s]\nname", returnValue);
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[ComponentBuilder::loadIDLFile FIM]\n\n");
#endif
throw returnValue;
} /* if */
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[ComponentBuilder::loadIDLFile FIM]\n\n");
#endif
}
}
}
......@@ -14,7 +14,7 @@ LDIR= ${OPENBUSLIB}
LIBS= dl tolua5.1
SRC= IComponentOil.cpp
SRC= IComponentOil.cpp ComponentBuilderOil.cpp
USE_LUA51=YES
USE_STATIC=YES
......
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