问题描述
我正在尝试建立一个CORBA应用程序,它有以下IDL接口:
I am trying to build a CORBA application, which has the following IDL interface:
module Chat {
exception SesionNoIniciada{};
exception UsuarioNoRegistrado{};
exception ErrorServidor{};
exception SesionYaIniciada{};
interface Cliente{
readonly attribute string nombre;
oneway void nuevaSolicitudDeAmistad(in string c); //devuelve void, parametro string/char*
oneway void actualizarListaAmigos();
oneway void nuevoMensaje(in Cliente usuario, in string men);
};
typedef sequence<string> nombres;
typedef sequence<Cliente> clientes;
interface Servidor{
nombres iniciarSesion(in Cliente usuario, in string pass) raises (UsuarioNoRegistrado, SesionYaIniciada);
void cerrarSesion(in Cliente usuario, in string pass) raises (SesionNoIniciada);
nombres getUsuariosRegistrados(in Cliente usuario, in string pass, in string nombre) raises (SesionNoIniciada);
nombres getAmigos(in Cliente usuario, in string pass) raises (SesionNoIniciada);
clientes getAmigosConectados(in Cliente usuario, in string pass) raises (SesionNoIniciada);
void nuevaSolicitudDeAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
void aceptarSolicitudDeAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
void rechazarSolicitudDeAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
void eliminarAmistad(in Cliente amigo1, in string pass, in string amigo2) raises (UsuarioNoRegistrado, SesionNoIniciada);
};
};
以下方法在返回行中给我一个分段错误:
The following method is giving me a segmentation fault in the return line:
nombres* Servidor_i::getAmigos(Cliente_ptr usuario, const char* pass){
vector<string> aux;
nombres_var result;
Cliente_ptr cliente;
try{
aux=bd.listarAmigos(usuario->nombre()); //Gets names from DB (currently 0)
result = new nombres(aux.size());
for(int i=0; i<aux.size(); i++) //This for is not being executed, since size is 0
result[i] = aux.at(i).c_str();
} catch(ErrorBD& e){
throw ErrorServidor();
}
cout << "Ending" << endl;
return result._retn();
}
我认为这将是与动态内存释放相关的东西,但我不是用于CORBA,所以我不确定我是否以正确的方式使用数据类型。
I think it will be something related to dynamic memory freeing, but I am not used to CORBA yet, so I'm not sure if I am using the data types in a proper way.
推荐答案
我不可能找到我的代码是什么错误,并产生我所说的分段错误;我想到了一个替代方法,我可以解决我的问题:我已经重建了IDL接口,以便该函数有一个'out'参数,这允许我返回一个序列没有任何问题。
Since it was impossible for me to find out what was wrong with my code, and generating the segmentation fault I have spoken about; I thought of an alternative way in which I could solve my problem: I have rebuilt the IDL interface so that the function has an 'out' parameter which allows me to return a sequence without any kind of problem.
这篇关于分割错误CORBA C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!