Discussion:
[omniORB] Passing a Sequence from Python to C++
EntonH
2008-02-15 17:29:02 UTC
Permalink
Hello,

I'm new to CORBA and Python and want to pass a sequence from Python to C++.

My IDL-file:

interface idlfile
{

struct param
{
string value1;
any value2;

};

typedef sequence param dict;

The generated code:
Struct:
class param:
def __init__(self, value1, value2)

Sequence:
class dict:
def __init__(self, *args, **kw)

I want to initialize the params in this way:
pm1 = idlfile.param("example1","example2")
But I don't know how to initialize the sequence?

How do I initialize a sequence of params und how do I pass them to C++?

Is it possible to put the sequence into a dictionary and to pass this to
C++?

I'm looking forward for your replies.

Greetings,
EntonH
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15495850.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
EntonH
2008-02-15 17:49:45 UTC
Permalink
Post by EntonH
Hello,
I'm new to CORBA and Python and want to pass a sequence from Python to C++.
interface idlfile
{
struct param
{
string value1;
any value2;
};
typedef sequence param dict;
def __init__(self, value1, value2)
def __init__(self, *args, **kw)
pm1 = idlfile.param("example1","example2")
But I don't know how to initialize the sequence?
How do I initialize a sequence of params und how do I pass them to C++?
Is it possible to put the sequence into a dictionary and to pass this to
C++?
I want to call a function - implemented in a C++ - dll - for which the
return _omnipy.invoke(self, "init",
_0_FuncLibRepository.dataLogger._d_init, args)
I'm looking forward for your replies.
Greetings,
EntonH
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15499626.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
Ridgway, Richard (London)
2008-02-15 17:53:19 UTC
Permalink
Sequences are mapped to python lists or tuples.
1.3.2 of the omg python languange mapping has this:

The sequence template is mapped to sequence objects (e.g., tuples or
lists).
Applications should not assume that values of a sequence type are
mutable. Sequences
and arrays of octets and characters are mapped to the string type for
efficiency reasons.
For example, given the IDL definitions
typedef sequence<long> LongList;
interface VectorOps{
long sum(in LongList l);
};
a client could invoke the operation
print obj.sum([1,2,3])



Thus in your case
sequence_of_params = [param1,param2]


-----Original Message-----
From: omniorb-list-***@omniorb-support.com
[mailto:omniorb-list-***@omniorb-support.com] On Behalf Of EntonH
Sent: 15 February 2008 11:29
To: omniorb-***@omniorb-support.com
Subject: [omniORB] Passing a Sequence from Python to C++



Hello,

I'm new to CORBA and Python and want to pass a sequence from Python to
C++.

My IDL-file:

interface idlfile
{

struct param
{
string value1;
any value2;

};

typedef sequence param dict;

The generated code:
Struct:
class param:
def __init__(self, value1, value2)

Sequence:
class dict:
def __init__(self, *args, **kw)

I want to initialize the params in this way:
pm1 = idlfile.param("example1","example2")
But I don't know how to initialize the sequence?

How do I initialize a sequence of params und how do I pass them to C++?

Is it possible to put the sequence into a dictionary and to pass this to
C++?

I'm looking forward for your replies.

Greetings,
EntonH
--
View this message in context:
http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp154958
50p15495850.html
Sent from the OmniORB - User mailing list archive at Nabble.com.


_______________________________________________
omniORB-list mailing list
omniORB-***@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--------------------------------------------------------

This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
--------------------------------------------------------
EntonH
2008-02-15 18:42:54 UTC
Permalink
Hello,

thanks for your reply.

I modified my idl-file like this:
struct param
{
string value1;
any value2;
};

typedef sequence param ParSeq;

any init(in ParSeq par_list);

So you think this should work?

list1 = []
list1.append( idlfile.param("Character",CORBA.Any(CORBA.TC_string,"good")))
list1.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(24))))

list2 = []
list2.append( idlfile.param("Character",CORBA.Any(CORBA.TC_string,"bad")))
list2.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(27))))

list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))

obj.init(list_all)

How should i modify my C++-function to accept this "par_list"?

Greetings,
EntonH






Sequences are mapped to python lists or tuples.
1.3.2 of the omg python languange mapping has this:

The sequence template is mapped to sequence objects (e.g., tuples or
lists).
Applications should not assume that values of a sequence type are
mutable. Sequences
and arrays of octets and characters are mapped to the string type for
efficiency reasons.
For example, given the IDL definitions
typedef sequence<long> LongList;
interface VectorOps{
long sum(in LongList l);
};
a client could invoke the operation
print obj.sum([1,2,3])



Thus in your case
sequence_of_params = [param1,param2]
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15500295.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
EntonH
2008-02-18 13:51:31 UTC
Permalink
Hello,

can't someone give me an advice how to do it? :o(
I still get the BAD_PARAM WronPythonType error... :o(

The funny thing about this error is the following:

When I'm passing a list of simple datatypes, the passing works - so I get an
message from a C++-function in the dll-File.

But when I'm trying to pass a list of structures I get the WrongPythonType
error.

Can someone help me out?

Greetings, EntonH
Post by EntonH
Hello,
thanks for your reply.
struct param
{
string value1;
any value2;
};
typedef sequence param ParSeq;
any init(in ParSeq par_list);
So you think this should work?
list1 = []
list1.append(
idlfile.param("Character",CORBA.Any(CORBA.TC_string,"good")))
list1.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(24))))
list2 = []
list2.append( idlfile.param("Character",CORBA.Any(CORBA.TC_string,"bad")))
list2.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(27))))
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))
obj.init(list_all)
How should i modify my C++-function to accept this "par_list"?
Greetings,
EntonH
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15540282.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
Gideon Guillen
2008-02-18 17:36:28 UTC
Permalink
Post by EntonH
can't someone give me an advice how to do it? :o(
I still get the BAD_PARAM WronPythonType error... :o(
[snipped]
Post by EntonH
typedef sequence param ParSeq;
....
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))
You can only use the primitive types and types that were defined on
your IDL on the "any" type.

Try using the following instead:
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA.TypeCode(ParSeq),list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA.TypeCode(ParSeq),list2)))
...
obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all)))
--
Gideon N. Guillen
***@gmail.com
entonh at gmx.de ()
2008-02-19 12:35:29 UTC
Permalink
Hello,
Post by Gideon Guillen
list_all = []
list_all.append
(idlfile.param("1",CORBA.Any(CORBA.TypeCode(ParSeq),list1)))
list_all.append
(idlfile.param("2",CORBA.Any(CORBA.TypeCode(ParSeq),list2)))
...
obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all)))
I'm getting the following error:
TypeError: Argument must be CORBA class or repository id.

What does this mean?

Greeting,
EntonH


-------- Original-Nachricht --------
Post by Gideon Guillen
Datum: Mon, 18 Feb 2008 19:36:39 +0800
Betreff: Re: [omniORB] Passing a Sequence from Python to C++
Post by EntonH
can't someone give me an advice how to do it? :o(
I still get the BAD_PARAM WronPythonType error... :o(
[snipped]
Post by EntonH
typedef sequence param ParSeq;
....
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))
You can only use the primitive types and types that were defined on
your IDL on the "any" type.
list_all = []
list_all.append
(idlfile.param("1",CORBA.Any(CORBA.TypeCode(ParSeq),list1)))
list_all.append
(idlfile.param("2",CORBA.Any(CORBA.TypeCode(ParSeq),list2)))
...
obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all)))
--
Gideon N. Guillen
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games!
http://games.entertainment.web.de/de/entertainment/games/free
entonh at gmx.de ()
2008-02-19 14:06:32 UTC
Permalink
Hello again,

the error I posted before solved itself so I didn't change anything in the code?!

When I call the init-function like you suggested
(obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all))))
I retrieve a BAD_PARAM_WrongPythonType error?!

When I call it like obj.init(list_all) the BAD_PARAM error is gone
but instead I get the following error:
COMM_FAILURE: Minor: COMM_FAILURE_WaitingForReply, COMPLETED_MAYBE.

Why I don't have to cast my list_all into an Any although it is defined in the idl-file: any init(in any list_all)

When is the COMM_FAILURE error thrown or where does it come from?

Do you have any ideas?

Greetings,
EntonH


-------- Original-Nachricht --------
Post by Gideon Guillen
Datum: Mon, 18 Feb 2008 19:36:39 +0800
Betreff: Re: [omniORB] Passing a Sequence from Python to C++
Post by EntonH
can't someone give me an advice how to do it? :o(
I still get the BAD_PARAM WronPythonType error... :o(
[snipped]
Post by EntonH
typedef sequence param ParSeq;
....
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))
You can only use the primitive types and types that were defined on
your IDL on the "any" type.
list_all = []
list_all.append
(idlfile.param("1",CORBA.Any(CORBA.TypeCode(ParSeq),list1)))
list_all.append
(idlfile.param("2",CORBA.Any(CORBA.TypeCode(ParSeq),list2)))
...
obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all)))
--
Gideon N. Guillen
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
Psssst! Schon vom neuen GMX MultiMessenger geh?rt?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
EntonH
2008-02-18 16:06:41 UTC
Permalink
Hello,

how can it be that n pass lists of simple datatypes but it's not possible to
pass lists of structures?
(With a list of structures I get the BAD_PARAM WrongPythonType error)
Do I have to create an instance of the sequence?

Greetings
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15542021.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
Duncan Grisby
2008-02-18 20:25:28 UTC
Permalink
On Sunday 17 February, EntonH wrote:

[...]
Post by EntonH
struct param
{
string value1;
any value2;
};
typedef sequence param ParSeq;
any init(in ParSeq par_list);
So you think this should work?
list1 = []
list1.append(
idlfile.param("Character",CORBA.Any(CORBA.TC_string,"good")))
list1.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(24))))
This is fine so far, although the mapping for CORBA long is Python int,
not Python long (which is an arbitrary scale integer). long can be used
where int is expected, though, so you'll get away with it.
Post by EntonH
list2 = []
list2.append( idlfile.param("Character",CORBA.Any(CORBA.TC_string,"bad")))
list2.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(27))))
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))
This is the problem. You're setting the value in the struct to an Any
that itself claims to contain an Any, but you've put in a list of param
structs. It will work if you use idlfile._tc_ParSeq, which is the
TypeCode of your ParSeq typedef.

This seems like a very contrived and complex example.

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
entonh at gmx.de ()
2008-02-19 12:43:29 UTC
Permalink
Hello,

I just found your answer and already tried it.
But like in my post before I'm getting the error:
TypeError: Argument must be CORBA class or repository id.

How can I solve this?

I tried both methods...and both ended up in the same error.

Greetings,
EntonH

-------- Original-Nachricht --------
Datum: Mon, 18 Feb 2008 14:25:40 +0000
Betreff: Re: [omniORB] Passing a Sequence from Python to C++
[...]
Post by EntonH
struct param
{
string value1;
any value2;
};
typedef sequence param ParSeq;
any init(in ParSeq par_list);
So you think this should work?
list1 = []
list1.append(
idlfile.param("Character",CORBA.Any(CORBA.TC_string,"good")))
list1.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(24))))
This is fine so far, although the mapping for CORBA long is Python int,
not Python long (which is an arbitrary scale integer). long can be used
where int is expected, though, so you'll get away with it.
Post by EntonH
list2 = []
list2.append(
idlfile.param("Character",CORBA.Any(CORBA.TC_string,"bad")))
Post by EntonH
list2.append( idlfile.param("Age",CORBA.Any(CORBA._tc_long,long(27))))
list_all = []
list_all.append (idlfile.param("1",CORBA.Any(CORBA._tc_any,list1)))
list_all.append (idlfile.param("2",CORBA.Any(CORBA._tc_any,list2)))
This is the problem. You're setting the value in the struct to an Any
that itself claims to contain an Any, but you've put in a list of param
structs. It will work if you use idlfile._tc_ParSeq, which is the
TypeCode of your ParSeq typedef.
This seems like a very contrived and complex example.
Duncan.
--
-- Duncan Grisby --
-- http://www.grisby.org --
--
Psssst! Schon vom neuen GMX MultiMessenger geh?rt?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
EntonH
2008-02-19 16:56:27 UTC
Permalink
Hello again,

the error I posted before solved itself so I didn't change anything in the
code?!

When I call the init-function like you suggested
(obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all))))
I retrieve a BAD_PARAM_WrongPythonType error?!

When I call it like obj.init(list_all) the BAD_PARAM error is gone
but instead I get the following error:
COMM_FAILURE: Minor: COMM_FAILURE_WaitingForReply, COMPLETED_MAYBE.

Why I don't have to cast my list_all into an Any although it is defined in
the idl-file: any init(in any list_all)

When is the COMM_FAILURE error thrown or where does it come from?

Do you have any ideas?

For your information:
I also wrote an application in C++ that uses the same idl-File. Everything
works just fine there, so ich can call my dll-File...this is so strange...
:-/

Greetings,
EntonH
Post by Duncan Grisby
This is the problem. You're setting the value in the struct to an Any
that itself claims to contain an Any, but you've put in a list of param
structs. It will work if you use idlfile._tc_ParSeq, which is the
TypeCode of your ParSeq typedef.
This seems like a very contrived and complex example.
Duncan.
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15560540.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
EntonH
2008-02-19 21:22:42 UTC
Permalink
Hello again,

the error I posted before solved itself so I didn't change anything in the
code?!

When I call the init-function like you suggested
(obj.init(CORBA.Any((CORBA.TypeCode(ParSeq),list_all))))
I retrieve a BAD_PARAM_WrongPythonType error?!

When I call it like obj.init(list_all) the BAD_PARAM error is gone
but instead I get the following error:
COMM_FAILURE: Minor: COMM_FAILURE_WaitingForReply, COMPLETED_MAYBE.

Why I don't have to cast my list_all into an Any although it is defined in
the idl-file: any init(in any list_all)

When is the COMM_FAILURE error thrown or where does it come from?

Do you have any ideas?

For your information:
I also wrote an application in C++ that uses the same idl-File. Everything
works just fine there, so ich can call my dll-File...this is so strange...
:-/

Greetings,
EntonH
Post by Duncan Grisby
This is the problem. You're setting the value in the struct to an Any
that itself claims to contain an Any, but you've put in a list of param
structs. It will work if you use idlfile._tc_ParSeq, which is the
TypeCode of your ParSeq typedef.
This seems like a very contrived and complex example.
Duncan.
--
View this message in context: http://www.nabble.com/Passing-a-Sequence-from-Python-to-C%2B%2B-tp15495850p15560540.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
Continue reading on narkive:
Loading...