Home Help Center

How to define a pointer type in slice?

acku711acku711 Member Zhang PpOrganization: NeusoftProject: R&D
Hi,

I have two questions.
1) I need to define an interface including an operation that accepts two arguments, one is int type, the other is char** type. How to define it?
2) If the argument is ostream*, How to define it?

Thanks for any help in advance.

Comments

  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    acku711 wrote: »
    Hi,
    1) I need to define an interface including an operation that accepts two arguments, one is int type, the other is char** type. How to define it?

    What are you trying to model here. That the operation returns a string? If so, you can use
    void op(out string s);
    
    2) If the argument is ostream*, How to define it?
    

    You cannot pass a C++ stream across a Slice interface. Doing so makes no sense. For example, if the receiver is written in Java, what could it possibly do with the stream?

    Even if the receiver were written in C++ too, what should happen if the receiver were to use the stream sent by the sender? If there receiver were to write some bytes to the stream, where would you expect them to appear? The couldn't appear on the sender's screen because a C++ stream is not capable of perform remote communication.

    I suggest you read the introductory chapter and the Slice chapter of the documentation to get an idea of what Ice can do for you, and how the basic architecture works.

    Cheers,

    Michi.

    Thanks for any help in advance.[/QUOTE]
  • acku711acku711 Member Zhang PpOrganization: NeusoftProject: R&D
    :) Thanks,Michi
    Sorry, maybe I have not described clearly.

    For the first question, I need to define an interface like that:

    int getOpt (int argc, char **argv)

    How to define argv in slice? I try to define this like that:

    sequence<byte> ByteSeq;
    sequence<ByteSeq> ByteseqSeq;
    int getOpt (int argc, ByteseqSeq argv);

    I don't feel it is better. In fact, I accept "(int argc, char **argv)" from command lines in client and pass to server through getOpt(). If the interface is defined like above, I have to rebuilt "ByteseqSeq" from char **argv. Is there another way?

    For the other question,

    I want to carry out a task that the client can get the output from server at real time. For example:

    supposing I can pass ostream& object int a function func(),

    interface demo
    {
    void func(out ostream& os); //I kown it is error here
    };

    ...
    void demo::func(ostream& os, const Ice::Current &)
    {
    int result = 0;
    while (1)
    {
    /* do something and come out result */

    os << result; /* then it will be printed in client */
    }
    }
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    For the first case you would be better off passing a sequence of string.
    sequence<string> StringSeq;
    

    You can find some predefined sequence types in slice/Ice/BuiltinSequences.ice.

    For the second case you'd have to define some interface through which the server streams the data. Something like:
    // Slice
    sequence<byte> ByteSeq;
    interface Stream
    {
        void send(ByteSeq data);
    };
    
    interface Server
    {
       void startStreaming(Stream* s);
    };
    

    In your client you would supply a proxy to a stream object to the server, and the server would call on the stream object passing the data as a series of byte sequences to the client.
Sign In or Register to comment.