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

[OPENBUS-92]

+ Primeira versão do Demo Hello do CPPOIL.
+ Adição de um método openbus->run() a lib CPPOIL. Tratamento de requisições CORBA para usuários C++ que estejam ofertando
um serviço. (uma primeira versão...)



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@85215 ae0415b3-e90b-0410-900d-d0be9363c56b
parent ee55173e
......@@ -74,6 +74,32 @@ namespace openbus {
return instance;
}
void Openbus::run() {
#if VERBOSE
cout << "[Openbus::run()]" << endl;
#endif
lua_getglobal(LuaVM, "run");
if (lua_pcall(LuaVM, 0, 0, 0) != 0) {
#if VERBOSE
cout << "\t[ERRO ao realizar pcall do metodo]" << endl;
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << endl;
cout << "\t[Tipo do elemento do TOPO: " << lua_typename(LuaVM, lua_type(LuaVM, -1)) << "]" << endl;
#endif
const char * errmsg ;
lua_getglobal(LuaVM, "tostring");
lua_insert(LuaVM, -2);
lua_pcall(LuaVM, 1, 1, 0);
errmsg = lua_tostring(LuaVM, -1);
lua_pop(LuaVM, 1);
#if VERBOSE
cout << "\t[lancando excecao: " << errmsg << "]" << endl;
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << "]" << endl;
cout << "[Openbus::run() FIM]" << endl << endl;
#endif
throw errmsg;
}
}
void Openbus::setClientInterceptor(common::ClientInterceptor* clientInterceptor) {
#if VERBOSE
cout << "[Openbus::setClientInterceptor() COMECO]" << endl;
......
......@@ -55,6 +55,7 @@ namespace openbus {
public:
~Openbus();
static Openbus* getInstance();
void run();
Lua_State* getLuaVM();
void setClientInterceptor(common::ClientInterceptor* clientInterceptor);
common::CredentialManager* getCredentialManager();
......
......@@ -48,3 +48,8 @@ function invoke(func, ...)
end --if
return select(2, unpack(res))
end
function run()
oil.main( function ()
end)
end
/*
** Demo Hello
** client.cpp
*/
#include <openbus.h>
#include "helloStub.h"
#include <iostream>
using namespace openbus;
using namespace std;
int main(int argc, char** argv) {
Openbus* openbus = Openbus::getInstance();
/* 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);
} 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();
/* Procurando o servico hello. */
services::PropertyList* propertyList = new services::PropertyList;
services::Property* property = new services::Property;
property->name = "facet";
property->value = new services::PropertyValue;
property->value->newmember("IHello");
propertyList->newmember(property);
services::ServiceOfferList* serviceOfferList = rgs->find(propertyList);
if (!serviceOfferList) {
cout << "** Nenhum servico hello foi encontrado no barramento." << endl;
exit(-1);
}
services::ServiceOffer* serviceOffer = serviceOfferList->getmember(0);
/* Obtendo o servico hello. */
scs::core::IComponent* member = serviceOffer->member;
member->loadidlfile("../idl/hello.idl");
IHello* hello = member->getFacet <IHello> ("IDL:demoidl/hello/IHello:1.0");
hello->sayHello();
return 0;
}
\ No newline at end of file
PROJNAME= client
APPNAME= ${PROJNAME}
OPENBUSINC = ${OPENBUS_HOME}/incpath
OPENBUSLIB = ${OPENBUS_HOME}/libpath/${TEC_UNAME}
OBJROOT= obj
TARGETROOT= bin
INCLUDES= ${OPENBUS_HOME}/core/utilities/cppoil ${OPENBUSINC}/tolua5.1 ${OPENBUSINC}/scs
LDIR= ${OPENBUSLIB} ${OPENBUS_HOME}/core/utilities/cppoil/lib/${TEC_UNAME}
LIBS= dl
SLIB= ${OPENBUS_HOME}/core/utilities/cppoil/lib/${TEC_UNAME}/libopenbus.a \
${OPENBUSLIB}/libftc.a \
${OPENBUSLIB}/libscsoil.a \
${OPENBUSLIB}/liboilall.a \
${OPENBUSLIB}/libscsall.a \
${OPENBUSLIB}/libluasocket.a \
${OPENBUSLIB}/libtolua5.1.a
SRC= client.cpp helloStub.cpp
USE_LUA51=YES
USE_STATIC=YES
\ No newline at end of file
/*
** Lua binding: hello
** Generated automatically by tolua 5.1b on Tue Nov 4 13:38:42 2008.
*/
#ifndef __cplusplus
#include "stdlib.h"
#endif
#include "string.h"
#include "tolua.h"
/* Exported function */
TOLUA_API int tolua_hello_open (lua_State* tolua_S);
LUALIB_API int luaopen_hello (lua_State* tolua_S);
#include "hello.hpp"
/* function to release collected object */
#ifdef __cplusplus
#else
static int tolua_collect (lua_State* tolua_S)
{
void* self = tolua_tousertype(tolua_S,1,0);
free(self);
return 0;
}
#endif
/* function to register type */
static void tolua_reg_types (lua_State* tolua_S)
{
tolua_usertype(tolua_S,"IHello");
}
/* method: new of class IHello */
static int tolua_hello_IHello_new00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"IHello",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
{
IHello* tolua_ret = (IHello*) new IHello();
tolua_pushusertype(tolua_S,(void*)tolua_ret,"IHello");
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
return 0;
#endif
}
/* method: delete of class IHello */
static int tolua_hello_IHello_delete00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"IHello",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
IHello* self = (IHello*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'delete'",NULL);
#endif
delete self;
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'delete'.",&tolua_err);
return 0;
#endif
}
/* method: sayHello of class IHello */
static int tolua_hello_IHello_sayHello00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"IHello",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
IHello* self = (IHello*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'sayHello'",NULL);
#endif
{
self->sayHello();
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'sayHello'.",&tolua_err);
return 0;
#endif
}
/* Open lib function */
LUALIB_API int luaopen_hello (lua_State* tolua_S)
{
tolua_open(tolua_S);
tolua_reg_types(tolua_S);
tolua_module(tolua_S,NULL,0);
tolua_beginmodule(tolua_S,NULL);
#ifdef __cplusplus
tolua_cclass(tolua_S,"IHello","IHello","",0);
#else
tolua_cclass(tolua_S,"IHello","IHello","",tolua_collect);
#endif
tolua_beginmodule(tolua_S,"IHello");
tolua_function(tolua_S,"new",tolua_hello_IHello_new00);
tolua_function(tolua_S,"delete",tolua_hello_IHello_delete00);
tolua_function(tolua_S,"sayHello",tolua_hello_IHello_sayHello00);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
return 1;
}
/* Open tolua function */
TOLUA_API int tolua_hello_open (lua_State* tolua_S)
{
lua_pushcfunction(tolua_S, luaopen_hello);
lua_pushstring(tolua_S, "hello");
lua_call(tolua_S, 1, 0);
return 1;
}
#include <iostream>
class IHello {
public:
IHello() {}
~IHello() {}
void sayHello() {
std::cout << "Hello!" << std::endl;
}
};
$#include "hello.hpp"
class IHello {
public:
IHello();
~IHello();
void sayHello();
};
/*
** helloStub.cpp
*/
#include <lua.hpp>
#include <openbus.h>
#include "helloStub.h"
static lua_State* LuaVM = 0;
IHello::IHello() {
if (!LuaVM) {
openbus::Openbus* openbus = openbus::Openbus::getInstance();
LuaVM = openbus->getLuaVM();
}
#if VERBOSE
printf("[IHello::IHello () COMECO]\n");
printf("\t[This: %p]\n", this);
#endif
#if VERBOSE
printf("[IHello::IHello() FIM]\n\n");
#endif
}
IHello::~IHello() {
/* empty */
}
void IHello::sayHello() {
#if VERBOSE
printf("[(%p)IHello::sayHello() COMECO]\n", this);
printf("\t[Tamanho da pilha de Lua: %d]\n", lua_gettop(LuaVM));
#endif
lua_getglobal(LuaVM, "invoke");
lua_pushlightuserdata(LuaVM, this);
lua_gettable(LuaVM, LUA_REGISTRYINDEX);
#if VERBOSE
printf("\t[IFile Lua:%p C++:%p]\n", \
lua_topointer(LuaVM, -1), this);
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
#endif
lua_getfield(LuaVM, -1, "sayHello");
#if VERBOSE
printf("\t[metodo getName empilhado]\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
lua_insert(LuaVM, -2);
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]\n", returnValue);
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[IHello::sayHello() FIM]\n\n");
#endif
throw returnValue;
} /* if */
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[IHello::sayHello() FIM]\n\n");
#endif
}
/*
** helloStub.h
*/
#ifndef HELLOSTUB_H_
#define HELLOSTUB_H_
class IHello {
public:
IHello();
~IHello();
void sayHello();
};
#endif
/*
** Demo Hello
** server.cpp
*/
#include <openbus.h>
#include "hello.hpp"
int tolua_hello_open (lua_State*);
#include <iostream>
using namespace openbus;
using namespace std;
int main(int argc, char** argv) {
Openbus* openbus = Openbus::getInstance();
/* 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);
} 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();
/* 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());
IHello* hello = new IHello;
member->addFacet("hello", "IDL:demoidl/hello/IHello:1.0", "IHello", hello);
/* Registrando no barramento o servico hello. */
services::PropertyList* propertyList = new services::PropertyList;
services::Property* property = new services::Property;
property->name = "facet";
services::PropertyValue* propertyValue = new services::PropertyValue;
propertyValue->newmember("IHello");
property->value = propertyValue;
propertyList->newmember(property);
services::ServiceOffer* serviceOffer = new services::ServiceOffer;
serviceOffer->properties = propertyList;
serviceOffer->member = member;
char* RegistryIdentifier;
rgs->Register(serviceOffer, RegistryIdentifier);
/* O processo fica no aguardo de requisies CORBA referentes ao servico hello. */
openbus->run();
return 0;
}
PROJNAME= server
APPNAME= ${PROJNAME}
OPENBUSINC = ${OPENBUS_HOME}/incpath
OPENBUSLIB = ${OPENBUS_HOME}/libpath/${TEC_UNAME}
OBJROOT= obj
TARGETROOT= bin
INCLUDES= ${OPENBUS_HOME}/core/utilities/cppoil ${OPENBUSINC}/tolua5.1 ${OPENBUSINC}/scs
LDIR= ${OPENBUSLIB} ${OPENBUS_HOME}/core/utilities/cppoil/lib/${TEC_UNAME}
LIBS= dl
SLIB= ${OPENBUS_HOME}/core/utilities/cppoil/lib/${TEC_UNAME}/libopenbus.a \
${OPENBUSLIB}/libftc.a \
${OPENBUSLIB}/libscsoil.a \
${OPENBUSLIB}/liboilall.a \
${OPENBUSLIB}/libscsall.a \
${OPENBUSLIB}/libluasocket.a \
${OPENBUSLIB}/libtolua5.1.a
SRC= server.cpp hello.cpp
USE_LUA51=YES
USE_STATIC=YES
\ No newline at end of file
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