[prev in list] [next in list] [prev in thread] [next in thread]
List: omniorb-list
Subject: [omniORB] Another test : Segmentation fault
From: JiangWei <jw.omni () sduept ! com>
Date: 2006-06-06 15:19:02
Message-ID: 44859CE6.9030502 () sduept ! com
[Download RAW message or body]
[jw@dell omni]$ ./a.out write x.bin
[jw@dell omni]$ ./a.out read x.bin
unmarshal...
Segmentation fault
["main.cpp" (text/x-c++src)]
#include "MyValue.hh"
#include <omniORB4/CORBA.h>
#include <fstream>
#include <iostream>
const bool CDR_BYTESWAP_FLAG = false;
CORBA::Any * get_an_any()
{
CORBA::Any * any = new CORBA::Any;
Test::ObjectStateSeq seq;
seq.length(6);
seq[0] = new OBV_Test::Transformer(0,"Hello",0,0);
seq[1] = new OBV_Test::Transformer(0,"World",0,0);
seq[2] = new OBV_Test::ObjectState(0,"omniORB4.1",0);
seq[3] = new OBV_Test::ObjectState(0,"is a great ORB",0);
seq[4] = seq[1];
seq[5] = seq[3];
(*any) <<= seq;
return any;
}
int main (int argc, char* argv[])
{
CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
orb->register_value_factory("IDL:Test/ObjectState:1.0", new Test::ObjectState_init);
orb->register_value_factory("IDL:Test/Transformer:1.0", new Test::Transformer_init);
if (argc == 3 && strcmp(argv[1] , "write") == 0)
{
CORBA::Any_var any = get_an_any();
cdrMemoryStream stream;
stream.setByteSwapFlag(CDR_BYTESWAP_FLAG);
stream.marshalBoolean(CDR_BYTESWAP_FLAG);
any.in() >>= stream;
std::ofstream outfile(argv[2]);
outfile.write((const char*)stream.bufPtr(),stream.bufSize());
outfile.close();
}
else if (argc == 3 && strcmp(argv[1] , "read") == 0)
{
std::ifstream infile(argv[2]);
infile.seekg(0,std::ios_base::end);
size_t size = infile.tellg();
infile.seekg(0,std::ios_base::beg);
char * buf = new char[size];
infile.read(buf,size);
cdrMemoryStream stream(buf);
stream.setByteSwapFlag(stream.unmarshalBoolean());
CORBA::Any any;
std::cout << "unmarshal..." << std::endl;
any <<= stream;
std::cout << " ... done" << std::endl;
Test::ObjectStateSeq * seq = NULL;
if(any >>= seq)
{
for(CORBA::ULong c=0; c<seq->length(); c++)
std::cout << "seq[" << c << "] = " << (*seq)[c]->name()
<< ",\tis a(n) " << (*seq)[c]->_NP_repositoryId() << std::endl;
}
else
std::cerr << "Bad Any" << std::endl;
} else {
std::cerr << "Usage:" << argv[0] <<" <read|write> filename " << std::endl;
}
orb->destroy();
return 0;
}
["MyValue.idl" (text/x-idl)]
module Test {
valuetype ObjectState
{
public unsigned long oid;
public string name;
public unsigned long pid;
};
typedef sequence<ObjectState> ObjectStateSeq;
valuetype Transformer : ObjectState
{
public long voltage_level;
};
};
["x.bin" (application/octet-stream)]
_______________________________________________
omniORB-list mailing list
omniORB-list@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic