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

[complemento ao commit r84907]



git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@84938 ae0415b3-e90b-0410-900d-d0be9363c56b
parent f2812dda
......@@ -636,6 +636,151 @@ namespace dataService {
return returnValue;
}
DataChannel* IDataEntry::getDataChannel() {
DataChannel* returnValue = NULL;
size_t size;
#if VERBOSE
printf("[(%p)IDataEntry::getDataChannel() 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[IDataEntry 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, "getDataChannel");
#if VERBOSE
printf("\t[metodo getDataChannel 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, 1, 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("[IDataEntry::getDataChannel() FIM]\n\n");
#endif
throw returnValue;
} /* if */
printf("\t[Tipo do elemento do TOPO: %s]\n" , \
lua_typename(LuaVM, lua_type(LuaVM, -1)));
returnValue = new DataChannel;
/* DataChannel->host */
#if VERBOSE
printf("\t[Gerando valor de retorno do tipo DataChannel]\n");
#endif
lua_getfield(LuaVM, -1, "host");
#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
const char * luastring = lua_tolstring(LuaVM, -1, &size);
returnValue->host = new char[size + 1];
memcpy((void*) returnValue->host, luastring, size);
returnValue->host[size] = '\0';
lua_pop(LuaVM, 1);
#if VERBOSE
printf("\t[DataChannel->host: %s]\n", returnValue->host);
#endif
/* 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");
#endif
lua_getfield(LuaVM, -1, "accessKey");
#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
const char* accessKeyStr = lua_tostring(LuaVM, -1);
OctetSeq* accessKey = new OctetSeq;
for (size = 0; size < strlen(accessKeyStr); size++) {
accessKey->newmember((char*) (accessKeyStr + size));
}
returnValue->accessKey = accessKey;
lua_pop(LuaVM, 1);
/* DataChannel->dataIdentifier */
lua_getfield(LuaVM, -1, "dataIdentifier");
#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
const char* dataIdentifierStr = lua_tostring(LuaVM, -1);
OctetSeq* dataIdentifier = new OctetSeq;
for (size = 0; size < strlen(dataIdentifierStr); size++) {
dataIdentifier->newmember((char*) (dataIdentifierStr + size));
}
returnValue->dataIdentifier = dataIdentifier;
lua_pop(LuaVM, 1);
#if VERBOSE
printf("\t[DataChannel->dataIdentifier: %s]\n", dataIdentifierStr);
#endif
/* DataChannel->writable */
lua_getfield(LuaVM, -1, "writable");
#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
returnValue->writable = lua_toboolean(LuaVM, -1);
#if VERBOSE
printf("\t[DataChannel->writable: %d]\n", returnValue->writable);
#endif
lua_pop(LuaVM, 1);
/* DataChannel->dataSize */
lua_getfield(LuaVM, -1, "dataSize");
#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
returnValue->dataSize = lua_tointeger(LuaVM, -1);
#if VERBOSE
printf("\t[DataChannel->dataSize: %lld]\n", returnValue->dataSize);
#endif
lua_pop(LuaVM, 1);
lua_pushlightuserdata(LuaVM, returnValue);
lua_insert(LuaVM, -2);
lua_settable(LuaVM, LUA_REGISTRYINDEX);
#if VERBOSE
printf("\t[Tamanho da pilha de Lua: %d]\n" , lua_gettop(LuaVM));
printf("[IDataEntry::getDataChannel() FIM]\n\n");
#endif
return returnValue;
}
IDataService::IDataService() {
openbus::Openbus* openbus = openbus::Openbus::getInstance();
LuaVM = openbus->getLuaVM();
......
......@@ -14,6 +14,8 @@
using namespace luaidl::cpp::types;
namespace dataService {
typedef luaidl::cpp::sequence<char> OctetSeq;
typedef luaidl::cpp::sequence<luaidl::cpp::types::Any> ValueList;
typedef char* MetadataName;
......@@ -41,6 +43,15 @@ namespace dataService {
typedef luaidl::cpp::sequence<Data> DataList;
struct DataChannel {
char* host;
unsigned short port;
OctetSeq* accessKey;
OctetSeq* dataIdentifier;
bool writable;
long long dataSize;
};
class IDataService;
class OperationNotSupported : public std::exception {};
......@@ -59,6 +70,7 @@ namespace dataService {
ValueList* getAttrs(scs::core::NameList* attrs_name);
bool setAttr(char* attr_name, luaidl::cpp::types::Any* attr_value);
bool setAttrs(scs::core::NameList* attrs_name, ValueList* attrs_value);
DataChannel* getDataChannel();
};
class IDataService {
......
......@@ -866,151 +866,6 @@ namespace projectService {
return returnValue;
}
DataChannel* IFile::getDataChannel() {
DataChannel* returnValue = NULL;
size_t size;
#if VERBOSE
printf("[(%p)IFile::getDataChannel() 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, "getDataChannel");
#if VERBOSE
printf("\t[metodo getDataChannel 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, 1, 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("[IFile::getDataChannel() FIM]\n\n");
#endif
throw returnValue;
} /* if */
printf("\t[Tipo do elemento do TOPO: %s]\n" , \
lua_typename(LuaVM, lua_type(LuaVM, -1)));
returnValue = new DataChannel;
/* DataChannel->host */
#if VERBOSE
printf("\t[Gerando valor de retorno do tipo DataChannel]\n");
#endif
lua_getfield(LuaVM, -1, "host");
#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
const char * luastring = lua_tolstring(LuaVM, -1, &size);
returnValue->host = new char[size + 1];
memcpy((void*) returnValue->host, luastring, size);
returnValue->host[size] = '\0';
lua_pop(LuaVM, 1);
#if VERBOSE
printf("\t[DataChannel->host: %s]\n", returnValue->host);
#endif
/* 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");
#endif
lua_getfield(LuaVM, -1, "accessKey");
#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
const char* accessKeyStr = lua_tostring(LuaVM, -1);
OctetSeq* accessKey = new OctetSeq;
for (size = 0; size < strlen(accessKeyStr); size++) {
accessKey->newmember((char*) (accessKeyStr + size));
}
returnValue->accessKey = accessKey;
lua_pop(LuaVM, 1);
/* DataChannel->fileIdentifier */
lua_getfield(LuaVM, -1, "fileIdentifier");
#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
const char* fileIdentifierStr = lua_tostring(LuaVM, -1);
OctetSeq* fileIdentifier = new OctetSeq;
for (size = 0; size < strlen(fileIdentifierStr); size++) {
fileIdentifier->newmember((char*) (fileIdentifierStr + size));
}
returnValue->fileIdentifier = fileIdentifier;
lua_pop(LuaVM, 1);
#if VERBOSE
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));
printf("\t[Tipo do elemento do TOPO: %s]\n" , \
lua_typename(LuaVM, lua_type(LuaVM, -1)));
#endif
returnValue->writable = lua_toboolean(LuaVM, -1);
#if VERBOSE
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));
printf("\t[Tipo do elemento do TOPO: %s]\n" , \
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);
lua_insert(LuaVM, -2);
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");
#endif
return returnValue;
}
void IFile::close() {
#if VERBOSE
printf("[(%p)IFile::close() COMECO]\n", this);
......
......@@ -13,8 +13,6 @@ using namespace luaidl::cpp::types;
namespace projectService {
typedef luaidl::cpp::sequence<char> OctetSeq;
class IFile;
class IProject : public dataService::IDataEntry {
......@@ -31,15 +29,6 @@ namespace projectService {
typedef luaidl::cpp::sequence<IProject> ProjectList;
typedef luaidl::cpp::sequence<IFile> FileList;
struct DataChannel {
char* host;
unsigned short port;
OctetSeq* accessKey;
OctetSeq* fileIdentifier;
bool writable;
long long fileSize;
};
class IFile : public dataService::IDataEntry {
public:
IFile();
......@@ -58,7 +47,6 @@ namespace projectService {
bool rename (char* newName);
bool moveFile(IFile* newParent);
bool copyFile(IFile* newParent);
DataChannel* getDataChannel();
void close();
};
......
......@@ -48,7 +48,7 @@ int main(int argc, char** argv) {
/* Adquirindo o servico de registro. */
services::IRegistryService* rgs = acs->getRegistryService();
/* Procurando o servico de dados do CSBase no barramento. */
/* Procurando o servico de projetos do CSBase no barramento. */
services::PropertyList* propertyList = new services::PropertyList;
services::Property* property = new services::Property;
property->name = "facets";
......@@ -75,18 +75,17 @@ int main(int argc, char** argv) {
dataKey->service_id = member->getComponentId();
dataKey->actual_data_id = fileName;
projectService::IFile* file;
projectService::DataChannel* dataChannel;
file = ds->getDataFacet <projectService::IFile> (dataKey, (char*) "IDL:openbusidl/ps/IFile:1.0");
if (!file) {
cout << "** Arquivo nao encontrado." << endl;
exit(-1);
}
/* Canal de acesso ao arquivo. */
dataChannel = file->getDataChannel();
size_t fileSize = dataChannel->fileSize;
dataService::DataChannel* dataChannel = file->getDataChannel();
size_t dataSize = dataChannel->dataSize;
/* Leitura do arquivo */
ftc* ch = new ftc(dataChannel->fileIdentifier->getmember(0), true, fileSize, dataChannel->host,
ftc* ch = new ftc(dataChannel->dataIdentifier->getmember(0), true, dataSize, dataChannel->host,
dataChannel->port, dataChannel->accessKey->getmember(0));
try {
ch->open(true);
......@@ -94,10 +93,10 @@ int main(int argc, char** argv) {
cout << "** Erro ao abrir arquivo: " << errmsg << endl;
exit(-1);
}
char* content = new char[fileSize];
ch->read(content, fileSize, 0);
char* content = new char[dataSize];
ch->read(content, dataSize, 0);
cout << "Eu li:";
for (size_t i = 0; i < fileSize; i++) {
for (size_t i = 0; i < dataSize; i++) {
cout << content[i];
}
cout << endl;
......
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