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

[OPENBUS-90]

* Pequenos ajustes no uso do I/O C++ e edentação.



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@84721 ae0415b3-e90b-0410-900d-d0be9363c56b
parent c90ccfbe
......@@ -10,9 +10,9 @@ extern "C" {
#include "luasocket.h"
}
#include "openbus.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <sstream>
using namespace std;
......@@ -30,7 +30,7 @@ namespace openbus {
void Openbus::initLuaVM(void) {
#if VERBOSE
printf("\t[Carregando bibliotecas de Lua...]\n");
cout << "\t[Carregando bibliotecas Lua.]" << endl;
#endif
luaL_openlibs(LuaVM);
luaL_findtable(LuaVM, LUA_GLOBALSINDEX, "package.preload", 1);
......@@ -40,7 +40,7 @@ namespace openbus {
luapreload_scsall(LuaVM);
scs::core::IComponent::setLuaVM(LuaVM);
#if VERBOSE
printf("\t[Tentando carregar arquivo openbus.lua...]\n");
cout << "\t[Tentando carregar arquivo openbus.lua...]" << endl;
#endif
luaopen_openbus(LuaVM);
lua_pop(LuaVM, 1);
......@@ -48,13 +48,13 @@ namespace openbus {
Openbus::Openbus() {
#if VERBOSE
printf("\n\n[Openbus::Openbus() COMECO]\n");
printf("\t[Criando instancia de Openbus]\n");
cout << endl << endl << "[Openbus::Openbus() COMECO]" << endl;
cout << "\t[Criando instancia de Openbus]" << endl;
#endif
LuaVM = lua_open();
initLuaVM();
#if VERBOSE
printf("[Openbus::Openbus() FIM]\n\n");
cout << "[Openbus::Openbus() FIM]" << endl;
#endif
}
......@@ -76,9 +76,9 @@ namespace openbus {
void Openbus::setClientInterceptor(common::ClientInterceptor* clientInterceptor) {
#if VERBOSE
printf("[Openbus::setClientInterceptor() COMECO]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("\t[Chamando metodo %s( %p )]\n", "oil.setClientInterceptor", clientInterceptor);
cout << "[Openbus::setClientInterceptor() COMECO]" << endl;
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << "]" << endl;
cout << "\t[Chamando metodo orb:setClientInterceptor(" << clientInterceptor << ")]" << endl;
#endif
lua_getglobal(LuaVM, "orb");
lua_getfield(LuaVM, -1, "setclientinterceptor");
......@@ -88,21 +88,21 @@ namespace openbus {
lua_pushlightuserdata(LuaVM, clientInterceptor);
lua_settable(LuaVM, -3);
#if VERBOSE
printf("\t[parametro {}.clientInterceptor (pointer) empilhado]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
cout << "\t[parametro {}.clientInterceptor (pointer) empilhado]" << endl;
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << "]" << endl;
#endif
lua_pushstring(LuaVM, "sendrequest");
lua_pushcfunction(LuaVM, common::ClientInterceptor::sendrequest);
lua_settable(LuaVM, -3);
#if VERBOSE
printf("\t[parametro {}.sendrequest (function) empilhado]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
cout << "\t[parametro {}.sendrequest (function) empilhado]" << endl;
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << "]" << endl;
#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)));
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");
......@@ -111,17 +111,16 @@ namespace openbus {
errmsg = lua_tostring(LuaVM, -1);
lua_pop(LuaVM, 1);
#if VERBOSE
printf("\t[lancando excecao]\n");
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[Openbus::setClientInterceptor() FIM]\n\n");
cout << "\t[lancando excecao]" << endl;
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << "]" << endl;
cout << "[Openbus::setClientInterceptor() FIM]" << endl << endl;
#endif
throw errmsg;
} /* if */
lua_pop(LuaVM, 1);
#if VERBOSE
/* retira a tabela oil */
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[Openbus::setClientInterceptor() FIM]\n\n");
cout << "\t[Tamanho da pilha de Lua: " << lua_gettop(LuaVM) << "]" << endl;
cout << "[Openbus::setClientInterceptor() FIM]" << endl << endl;
#endif
}
......
......@@ -10,9 +10,9 @@ oil.orb = orb
oilcorbaidlstring = oil.corba.idl.string
orb:loadidlfile( os.getenv( "OPENBUS_HOME" ).."/idlpath/access_control_service.idl" )
orb:loadidlfile( os.getenv( "OPENBUS_HOME" ).."/idlpath/registry_service.idl" )
orb:loadidlfile( os.getenv( "OPENBUS_HOME" ).."/idlpath/session_service.idl" )
orb:loadidlfile(os.getenv("OPENBUS_HOME" ).."/idlpath/access_control_service.idl")
orb:loadidlfile(os.getenv("OPENBUS_HOME" ).."/idlpath/registry_service.idl")
orb:loadidlfile(os.getenv("OPENBUS_HOME" ).."/idlpath/session_service.idl")
local lir = orb:getLIR()
......@@ -20,14 +20,14 @@ IComponent = require 'scs.core.IComponent'
oil.verbose:level(0)
oil.tasks.verbose:level(0)
--oil.tasks.verbose:flag("threads", true)
oil.tasks.verbose:flag("threads", false)
-- Metodo utilizado pelo interceptador do OiL
function sendrequest(credential, credentialType, contextID, request)
local encoder = orb:newencoder()
encoder:put(credential, lir:lookup_id(credentialType).type)
request.service_context = {
{ context_id = contextID, context_data = encoder:getdata() }
{context_id = contextID, context_data = encoder:getdata()}
}
end
......@@ -37,14 +37,14 @@ if not oil.isrunning then
end
-- Invoke with concurrency
function invoke( func, ... )
function invoke(func, ...)
local res
oil.main ( function()
res = { oil.pcall( func, unpack( arg ) ) }
oil.main (function()
res = {oil.pcall(func, unpack(arg))}
oil.tasks:halt()
end )
if ( not res[ 1 ] ) then
error( res[ 2 ] )
if (not res[1]) then
error(res[2])
end --if
return select( 2, unpack( res ) )
return select(2, unpack(res))
end
......@@ -499,7 +499,7 @@ namespace projectService {
#if VERBOSE
printf("\t[lancando excecao %s]\n", returnValue);
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[IFile::getDataChannel() FIM]\n\n");
printf("[IFile::getProject() FIM]\n\n");
#endif
throw returnValue;
} /* if */
......@@ -511,7 +511,7 @@ namespace projectService {
lua_settable(LuaVM, LUA_REGISTRYINDEX);
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[IFile::getDataChannel() FIM]\n\n");
printf("[IFile::getProject() FIM]\n\n");
#endif
return returnValue;
}
......@@ -915,7 +915,6 @@ namespace projectService {
/* DataChannel->host */
#if VERBOSE
printf("\t[Gerando valor de retorno do tipo DataChannel]\n");
printf("\t[DataChannel->host]\n");
#endif
lua_getfield(LuaVM, -1, "host");
#if VERBOSE
......@@ -928,18 +927,21 @@ namespace projectService {
memcpy((void*) returnValue->host, luastring, size);
returnValue->host[size] = '\0';
lua_pop(LuaVM, 1);
/* DataChannel->port */
#if VERBOSE
printf("\t[DataChannel->port]\n");
printf("\t[DataChannel->host: %s]\n", returnValue->host);
#endif
lua_getfield(LuaVM, -1, "port");
/* DataChannel->port */
#if VERBOSE
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_getfield(LuaVM, -1, "port");
returnValue->port = lua_tointeger(LuaVM, -1);
lua_pop(LuaVM, 1);
#if VERBOSE
printf("\t[DataChannel->port: %u]\n", returnValue->port);
#endif
/* DataChannel->accessKey */
#if VERBOSE
printf("\t[DataChannel->accessKey]\n");
......@@ -958,9 +960,6 @@ namespace projectService {
returnValue->accessKey = accessKey;
lua_pop(LuaVM, 1);
/* DataChannel->fileIdentifier */
#if VERBOSE
printf("\t[DataChannel->fileIdentifier]\n");
#endif
lua_getfield(LuaVM, -1, "fileIdentifier");
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
......@@ -974,10 +973,10 @@ namespace projectService {
}
returnValue->fileIdentifier = fileIdentifier;
lua_pop(LuaVM, 1);
/* DataChannel->writable */
#if VERBOSE
printf("\t[DataChannel->writable]\n");
printf("\t[DataChannel->fileIdentifier: %s]\n", fileIdentifierStr);
#endif
/* DataChannel->writable */
lua_getfield(LuaVM, -1, "writable");
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
......@@ -985,11 +984,11 @@ namespace projectService {
lua_typename(LuaVM, lua_type(LuaVM, -1)));
#endif
returnValue->writable = lua_toboolean(LuaVM, -1);
lua_pop(LuaVM, 1);
/* DataChannel->fileSize */
#if VERBOSE
printf("\t[DataChannel->fileSize]\n");
printf("\t[DataChannel->writable: %d]\n", returnValue->writable);
#endif
lua_pop(LuaVM, 1);
/* DataChannel->fileSize */
lua_getfield(LuaVM, -1, "fileSize");
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
......@@ -997,6 +996,9 @@ namespace projectService {
lua_typename(LuaVM, lua_type(LuaVM, -1)));
#endif
returnValue->fileSize = lua_tointeger(LuaVM, -1);
#if VERBOSE
printf("\t[DataChannel->fileSize: %lld]\n", returnValue->fileSize);
#endif
lua_pop(LuaVM, 1);
lua_pushlightuserdata(LuaVM, returnValue);
......
......@@ -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. */
/**************************************************************************************************/
......@@ -19,14 +19,12 @@
#include "../IProjectService.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
using namespace openbus;
int main(int argc, char** argv) {
char PSIDL[256];
if (argc != 2) {
cout << "Uso: demo <projeto>/<arquivo>" << endl;
return 0;
......@@ -65,10 +63,9 @@ int main(int argc, char** argv) {
services::ServiceOffer* serviceOffer = serviceOfferList->getmember(0);
scs::core::IComponent* member = serviceOffer->member;
const char* OPENBUS_HOME = getenv("OPENBUS_HOME");
strcpy(PSIDL, OPENBUS_HOME);
strcat(PSIDL, "/idlpath/project_service.idl");
member->loadidlfile(PSIDL);
string PSIDLPath(getenv("OPENBUS_HOME"));
PSIDLPath += "/idlpath/project_service.idl";
member->loadidlfile(PSIDLPath.c_str());
/* Obtendo o servio de dados. */
dataService::IDataService* ds = member->getFacet <dataService::IDataService> ("IDL:openbusidl/ds/IDataService:1.0");
......
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