Ejemplo n.º 1
0
    public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
    {
        outParams = null;

        Ice.Communicator communicator = current.adapter.getCommunicator();

        Ice.InputStream inStream = null;
        if (inParams.Length > 0)
        {
            inStream = new Ice.InputStream(communicator, inParams);
            inStream.startEncapsulation();
        }

        if (current.operation.Equals("printString"))
        {
            string message = inStream.readString();
            inStream.endEncapsulation();
            Console.WriteLine("Printing string `" + message + "'");
            return(true);
        }
        else if (current.operation.Equals("printStringSequence"))
        {
            String[] seq = Demo.StringSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing string sequence {");
            for (int i = 0; i < seq.Length; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write("'" + seq[i] + "'");
            }
            Console.WriteLine("}");
            return(true);
        }
        else if (current.operation.Equals("printDictionary"))
        {
            Dictionary <string, string> dict = Demo.StringDictHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing dictionary {");
            bool first = true;
            foreach (KeyValuePair <string, string> e in dict)
            {
                if (!first)
                {
                    Console.Write(", ");
                }
                first = false;
                Console.Write(e.Key + "=" + e.Value);
            }
            Console.WriteLine("}");
            return(true);
        }
        else if (current.operation.Equals("printEnum"))
        {
            Demo.Color c = Demo.ColorHelper.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing enum " + c);
            return(true);
        }
        else if (current.operation.Equals("printStruct"))
        {
            Demo.Structure s = Demo.Structure.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value);
            return(true);
        }
        else if (current.operation.Equals("printStructSequence"))
        {
            Demo.Structure[] seq = Demo.StructureSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing struct sequence: {");
            for (int i = 0; i < seq.Length; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write(seq[i].name + "=" + seq[i].value);
            }
            Console.WriteLine("}");
            return(true);
        }
        else if (current.operation.Equals("printClass"))
        {
            ReadValueCallback cb = new ReadValueCallback();
            inStream.readValue(cb.invoke);
            inStream.readPendingValues();
            inStream.endEncapsulation();
            Demo.C c = cb.obj as Demo.C;
            Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value);
            return(true);
        }
        else if (current.operation.Equals("getValues"))
        {
            Demo.C c = new Demo.C();
            c.s       = new Demo.Structure();
            c.s.name  = "green";
            c.s.value = Demo.Color.green;
            Ice.OutputStream outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeValue(c);
            outStream.writeString("hello");
            outStream.writePendingValues();
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return(true);
        }
        else if (current.operation.Equals("throwPrintFailure"))
        {
            Console.WriteLine("Throwing PrintFailure");
            Demo.PrintFailure ex = new Demo.PrintFailure();
            ex.reason = "paper tray empty";
            Ice.OutputStream outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeException(ex);
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return(false);
        }
        else if (current.operation.Equals("shutdown"))
        {
            current.adapter.getCommunicator().shutdown();
            return(true);
        }
        else
        {
            Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
            ex.id        = current.id;
            ex.facet     = current.facet;
            ex.operation = current.operation;
            throw ex;
        }
    }
Ejemplo n.º 2
0
    private static int run(Ice.Communicator communicator)
    {
        var obj = communicator.propertyToProxy("Printer.Proxy");

        menu();

        string line = null;

        do
        {
            try
            {
                Console.Write("==> ");
                Console.Out.Flush();
                line = Console.In.ReadLine();
                if (line == null)
                {
                    break;
                }

                byte[] outParams;

                if (line.Equals("1"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    var outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    outStream.writeString("The streaming API works!");
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(),
                                        out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("2"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    var outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    string[] arr = { "The", "streaming", "API", "works!" };
                    StringSeqHelper.write(outStream, arr);
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(),
                                        out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("3"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    var outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    var dict = new Dictionary <string, string>()
                    {
                        { "The", "streaming" },
                        { "API", "works!" }
                    };
                    StringDictHelper.write(outStream, dict);
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(),
                                        out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("4"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    var outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    ColorHelper.write(outStream, Color.green);
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("5"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    var outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    var s = new Structure("red", Color.red);
                    Structure.ice_write(outStream, s);
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(),
                                        out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("6"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    var outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    Structure[] arr =
                    {
                        new Structure("red",   Color.red),
                        new Structure("green", Color.green),
                        new Structure("blue",  Color.blue)
                    };
                    StructureSeqHelper.write(outStream, arr);
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(),
                                        out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("7"))
                {
                    //
                    // Marshal the in parameter.
                    //
                    Ice.OutputStream outStream = new Ice.OutputStream(communicator);
                    outStream.startEncapsulation();
                    var c = new C(new Structure("blue", Color.blue));
                    outStream.writeValue(c);
                    outStream.writePendingValues();
                    outStream.endEncapsulation();

                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                }
                else if (line.Equals("8"))
                {
                    //
                    // Invoke operation.
                    //
                    if (!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams))
                    {
                        Console.Error.WriteLine("Unknown user exception");
                        continue;
                    }

                    //
                    // Unmarshal the results.
                    //
                    var inStream = new Ice.InputStream(communicator, outParams);
                    inStream.startEncapsulation();
                    var cb = new ReadValueCallback();
                    inStream.readValue(cb.invoke);
                    var str = inStream.readString();
                    inStream.readPendingValues();
                    var c = cb.obj as C;
                    Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name +
                                            ", s.value=" + c.s.value);
                }
                else if (line.Equals("9"))
                {
                    //
                    // Invoke operation.
                    //
                    if (obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams))
                    {
                        Console.Error.WriteLine("Expected exception");
                        continue;
                    }

                    var inStream = new Ice.InputStream(communicator, outParams);
                    inStream.startEncapsulation();
                    try
                    {
                        inStream.throwException();
                    }
                    catch (PrintFailure)
                    {
                        // Expected.
                    }
                    catch (Ice.UserException)
                    {
                        Console.Error.WriteLine("Unknown user exception");
                    }
                    inStream.endEncapsulation();
                }
                else if (line.Equals("s"))
                {
                    obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams);
                }
                else if (line.Equals("x"))
                {
                    // Nothing to do.
                }
                else if (line.Equals("?"))
                {
                    menu();
                }
                else
                {
                    Console.Error.WriteLine("unknown command `" + line + "'");
                    menu();
                }
            }
            catch (Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
            }
        }while(!line.Equals("x"));

        return(0);
    }
Ejemplo n.º 3
0
    public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
    {
        outParams = null;
        bool result = true;

        var communicator = current.adapter.getCommunicator();

        Ice.InputStream inStream = null;
        if (inParams.Length > 0)
        {
            inStream = new Ice.InputStream(communicator, inParams);
            inStream.startEncapsulation();
        }

        if (current.operation.Equals("printString"))
        {
            var message = inStream.readString();
            Console.WriteLine("Printing string `" + message + "'");
        }
        else if (current.operation.Equals("printStringSequence"))
        {
            var seq = StringSeqHelper.read(inStream);
            Console.Write("Printing string sequence {");
            for (int i = 0; i < seq.Length; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write("'" + seq[i] + "'");
            }
            Console.WriteLine("}");
        }
        else if (current.operation.Equals("printDictionary"))
        {
            var dict = StringDictHelper.read(inStream);
            Console.Write("Printing dictionary {");
            bool first = true;
            foreach (var e in dict)
            {
                if (!first)
                {
                    Console.Write(", ");
                }
                first = false;
                Console.Write(e.Key + "=" + e.Value);
            }
            Console.WriteLine("}");
        }
        else if (current.operation.Equals("printEnum"))
        {
            var c = ColorHelper.read(inStream);
            Console.WriteLine("Printing enum " + c);
        }
        else if (current.operation.Equals("printStruct"))
        {
            var s = Structure.ice_read(inStream);
            Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value);
        }
        else if (current.operation.Equals("printStructSequence"))
        {
            var seq = StructureSeqHelper.read(inStream);
            Console.Write("Printing struct sequence: {");
            for (int i = 0; i < seq.Length; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write(seq[i].name + "=" + seq[i].value);
            }
            Console.WriteLine("}");
        }
        else if (current.operation.Equals("printClass"))
        {
            var cb = new ReadValueCallback();
            inStream.readValue(cb.invoke);
            inStream.readPendingValues();
            var c = cb.obj as C;
            Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value);
        }
        else if (current.operation.Equals("getValues"))
        {
            var c         = new C(new Structure("green", Color.green));
            var outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeValue(c);
            outStream.writeString("hello");
            outStream.writePendingValues();
            outStream.endEncapsulation();
            outParams = outStream.finished();
        }
        else if (current.operation.Equals("throwPrintFailure"))
        {
            Console.WriteLine("Throwing PrintFailure");
            var ex        = new PrintFailure("paper tray empty");
            var outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeException(ex);
            outStream.endEncapsulation();
            outParams = outStream.finished();
            result    = false;
        }
        else if (current.operation.Equals("shutdown"))
        {
            current.adapter.getCommunicator().shutdown();
        }
        else
        {
            throw new Ice.OperationNotExistException(current.id, current.facet, current.operation);
        }

        //
        // Make sure we read all in parameters
        //
        inStream.endEncapsulation();
        return(result);
    }
Ejemplo n.º 4
0
        public override int run(string[] args)
        {
            if (args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return(1);
            }

            Ice.ObjectPrx obj = communicator().propertyToProxy("Printer.Proxy");

            menu();

            string line = null;

            do
            {
                try
                {
                    Console.Write("==> ");
                    Console.Out.Flush();
                    line = Console.In.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    byte[] outParams;

                    if (line.Equals("1"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        outStream.writeString("The streaming API works!");
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("2"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        string[] arr = { "The", "streaming", "API", "works!" };
                        Demo.StringSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("3"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Dictionary <string, string> dict = new Dictionary <string, string>();
                        dict["The"] = "streaming";
                        dict["API"] = "works!";
                        Demo.StringDictHelper.write(outStream, dict);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("4"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.ColorHelper.write(outStream, Demo.Color.green);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("5"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.Structure s = new Demo.Structure();
                        s.name  = "red";
                        s.value = Demo.Color.red;
                        Demo.Structure.write(outStream, s);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("6"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.Structure[] arr = new Demo.Structure[3];
                        arr[0]       = new Demo.Structure();
                        arr[0].name  = "red";
                        arr[0].value = Demo.Color.red;
                        arr[1]       = new Demo.Structure();
                        arr[1].name  = "green";
                        arr[1].value = Demo.Color.green;
                        arr[2]       = new Demo.Structure();
                        arr[2].name  = "blue";
                        arr[2].value = Demo.Color.blue;
                        Demo.StructureSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(),
                                            out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("7"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Demo.C c = new Demo.C();
                        c.s       = new Demo.Structure();
                        c.s.name  = "blue";
                        c.s.value = Demo.Color.blue;
                        outStream.writeValue(c);
                        outStream.writePendingValues();
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if (line.Equals("8"))
                    {
                        //
                        // Invoke operation.
                        //
                        if (!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                            continue;
                        }

                        //
                        // Unmarshal the results.
                        //
                        Ice.InputStream inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        ReadValueCallback cb = new ReadValueCallback();
                        inStream.readValue(cb.invoke);
                        String str = inStream.readString();
                        inStream.readPendingValues();
                        Demo.C c = cb.obj as Demo.C;
                        Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name +
                                                ", s.value=" + c.s.value);
                    }
                    else if (line.Equals("9"))
                    {
                        //
                        // Invoke operation.
                        //
                        if (obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Expected exception");
                            continue;
                        }

                        Ice.InputStream inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        try
                        {
                            inStream.throwException();
                        }
                        catch (Demo.PrintFailure)
                        {
                            // Expected.
                        }
                        catch (Ice.UserException)
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                        inStream.endEncapsulation();
                    }
                    else if (line.Equals("s"))
                    {
                        obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams);
                    }
                    else if (line.Equals("x"))
                    {
                        // Nothing to do.
                    }
                    else if (line.Equals("?"))
                    {
                        menu();
                    }
                    else
                    {
                        Console.Error.WriteLine("unknown command `" + line + "'");
                        menu();
                    }
                }
                catch (Ice.LocalException ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }while(!line.Equals("x"));

            return(0);
        }
Ejemplo n.º 5
0
 internal override void readValue(ReadValueCallback cb)
 {
     int index = _stream.readSize();
     if(index < 0)
     {
         throw new Ice.MarshalException("invalid object id");
     }
     else if(index == 0)
     {
         if(cb != null)
         {
             cb(null);
         }
     }
     else if(_current != null && (_current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) != 0)
     {
         //
         // When reading an instance within a slice and there's an
         // indirect instance table, always read an indirect reference
         // that points to an instance from the indirect instance table
         // marshaled at the end of the Slice.
         //
         // Maintain a list of indirect references. Note that the
         // indirect index starts at 1, so we decrement it by one to
         // derive an index into the indirection table that we'll read
         // at the end of the slice.
         //
         if(cb != null)
         {
             if(_current.indirectPatchList == null)
             {
                 _current.indirectPatchList = new Stack<IndirectPatchEntry>();
             }
             IndirectPatchEntry e = new IndirectPatchEntry();
             e.index = index - 1;
             e.patcher = cb;
             _current.indirectPatchList.Push(e);
         }
     }
     else
     {
         readInstance(index, cb);
     }
 }
Ejemplo n.º 6
0
            private int readInstance(int index, ReadValueCallback cb)
            {
                Debug.Assert(index > 0);

                if(index > 1)
                {
                    if(cb != null)
                    {
                        addPatchEntry(index, cb);
                    }
                    return index;
                }

                push(SliceType.ValueSlice);

                //
                // Get the instance ID before we start reading slices. If some
                // slices are skipped, the indirect instance table are still read and
                // might read other instances.
                //
                index = ++_valueIdIndex;

                //
                // Read the first slice header.
                //
                startSlice();
                string mostDerivedId = _current.typeId;
                Ice.Object v = null;
                while(true)
                {
                    bool updateCache = false;

                    if(_current.compactId >= 0)
                    {
                        updateCache = true;

                        //
                        // Translate a compact (numeric) type ID into a class.
                        //
                        if(_compactIdCache == null)
                        {
                            _compactIdCache = new Dictionary<int, Type>(); // Lazy initialization.
                        }
                        else
                        {
                            //
                            // Check the cache to see if we've already translated the compact type ID into a class.
                            //
                            Type cls = null;
                            _compactIdCache.TryGetValue(_current.compactId, out cls);
                            if(cls != null)
                            {
                                try
                                {
                                    Debug.Assert(!cls.IsAbstract && !cls.IsInterface);
                                    v = (Ice.Object)IceInternal.AssemblyUtil.createInstance(cls);
                                    updateCache = false;
                                }
                                catch(Exception ex)
                                {
                                    throw new NoValueFactoryException("no value factory", "compact ID " +
                                                                      _current.compactId, ex);
                                }
                            }
                        }

                        //
                        // If we haven't already cached a class for the compact ID, then try to translate the
                        // compact ID into a type ID.
                        //
                        if(v == null)
                        {
                            _current.typeId = "";
                            if(_compactIdResolver != null)
                            {
                                try
                                {
                                    _current.typeId = _compactIdResolver(_current.compactId);
                                }
                                catch(Ice.LocalException)
                                {
                                    throw;
                                }
                                catch(System.Exception ex)
                                {
                                    throw new Ice.MarshalException("exception in CompactIdResolver for ID " +
                                                                   _current.compactId, ex);
                                }
                            }

                            if(_current.typeId.Length == 0)
                            {
                                _current.typeId = _stream.instance().resolveCompactId(_current.compactId);
                            }
                        }
                    }

                    if(v == null && _current.typeId.Length > 0)
                    {
                        v = newInstance(_current.typeId);
                    }

                    if(v != null)
                    {
                        if(updateCache)
                        {
                            Debug.Assert(_current.compactId >= 0);
                            _compactIdCache.Add(_current.compactId, v.GetType());
                        }

                        //
                        // We have an instance, get out of this loop.
                        //
                        break;
                    }

                    //
                    // If slicing is disabled, stop unmarshaling.
                    //
                    if(!_sliceValues)
                    {
                        throw new NoValueFactoryException("no value factory found and slicing is disabled",
                                                          _current.typeId);
                    }

                    //
                    // Slice off what we don't understand.
                    //
                    skipSlice();

                    //
                    // If this is the last slice, keep the instance as an opaque
                    // UnknownSlicedValue object.
                    //
                    if((_current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) != 0)
                    {
                        //
                        // Provide a factory with an opportunity to supply the instance.
                        // We pass the "::Ice::Object" ID to indicate that this is the
                        // last chance to preserve the instance.
                        //
                        v = newInstance(Ice.ObjectImpl.ice_staticId());
                        if(v == null)
                        {
                            v = new Ice.UnknownSlicedValue(mostDerivedId);
                        }

                        break;
                    }

                    startSlice(); // Read next Slice header for next iteration.
                }

                //
                // Unmarshal the instance.
                //
                unmarshal(index, v);

                if(_current == null && _patchMap != null && _patchMap.Count > 0)
                {
                    //
                    // If any entries remain in the patch map, the sender has sent an index for an instance, but failed
                    // to supply the instance.
                    //
                    throw new Ice.MarshalException("index for class received, but no instance");
                }

                if(cb != null)
                {
                    cb(v);
                }
                return index;
            }
Ejemplo n.º 7
0
            protected void addPatchEntry(int index, ReadValueCallback cb)
            {
                Debug.Assert(index > 0);

                //
                // Check if we already unmarshaled the instance. If that's the case,
                // just call the callback and we're done.
                //
                Ice.Object obj;
                if(_unmarshaledMap.TryGetValue(index, out obj))
                {
                    cb(obj);
                    return;
                }

                if(_patchMap == null)
                {
                    _patchMap = new Dictionary<int, LinkedList<ReadValueCallback>>();
                }

                //
                // Add patch entry if the instance isn't unmarshaled yet,
                // the callback will be called when the instance is
                // unmarshaled.
                //
                LinkedList<ReadValueCallback> l;
                if(!_patchMap.TryGetValue(index, out l))
                {
                    //
                    // We have no outstanding instances to be patched for this
                    // index, so make a new entry in the patch map.
                    //
                    l = new LinkedList<ReadValueCallback>();
                    _patchMap.Add(index, l);
                }

                //
                // Append a patch entry for this instance.
                //
                l.AddLast(cb);
            }
Ejemplo n.º 8
0
            internal override void readValue(ReadValueCallback cb)
            {
                Debug.Assert(cb != null);

                //
                // Object references are encoded as a negative integer in 1.0.
                //
                int index = _stream.readInt();
                if(index > 0)
                {
                    throw new Ice.MarshalException("invalid object id");
                }
                index = -index;

                if(index == 0)
                {
                    cb(null);
                }
                else
                {
                    addPatchEntry(index, cb);
                }
            }
Ejemplo n.º 9
0
 internal abstract void readValue(ReadValueCallback cb);
Ejemplo n.º 10
0
 /// <summary>
 /// Extracts the index of an optional Slice value from the stream.
 /// </summary>
 /// <param name="tag">The numeric tag associated with the value.</param>
 /// <param name="cb">The callback to notify the application when the extracted instance is available (if any).
 /// The stream extracts Slice values in stages. The Ice run time invokes the delegate when the
 /// corresponding instance has been fully unmarshaled.</param>
 public void readValue(int tag, ReadValueCallback cb)
 {
     if(readOptional(tag, Ice.OptionalFormat.Class))
     {
         readValue(cb);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Extracts the index of a Slice value from the stream.
 /// </summary>
 /// <param name="cb">The callback to notify the application when the extracted instance is available.
 /// The stream extracts Slice values in stages. The Ice run time invokes the delegate when the
 /// corresponding instance has been fully unmarshaled.</param>
 public void readValue(ReadValueCallback cb)
 {
     initEncaps();
     _encapsStack.decoder.readValue(cb);
 }
Ejemplo n.º 12
0
        public override int run(string[] args)
        {
            if(args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return 1;
            }

            var obj = communicator().propertyToProxy("Printer.Proxy");

            menu();

            string line = null;
            do
            {
                try
                {
                    Console.Write("==> ");
                    Console.Out.Flush();
                    line = Console.In.ReadLine();
                    if(line == null)
                    {
                        break;
                    }

                    byte[] outParams;

                    if(line.Equals("1"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        outStream.writeString("The streaming API works!");
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("2"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        string[] arr = { "The", "streaming", "API", "works!" };
                        StringSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("3"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        var dict = new Dictionary<string, string>()
                            {
                                { "The", "streaming" },
                                { "API", "works!"}
                            };
                        StringDictHelper.write(outStream, dict);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("4"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        ColorHelper.write(outStream, Color.green);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("5"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        var s = new Structure("read", Color.red);
                        Structure.write(outStream, s);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("6"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Structure[] arr =
                            {
                                new Structure("red", Color.red),
                                new Structure("green", Color.green),
                                new Structure("blue", Color.blue)
                            };
                        StructureSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("7"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        var c = new C(new Structure("blue", Color.blue));
                        outStream.writeValue(c);
                        outStream.writePendingValues();
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("8"))
                    {
                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                            continue;
                        }

                        //
                        // Unmarshal the results.
                        //
                        var inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        var cb = new ReadValueCallback();
                        inStream.readValue(cb.invoke);
                        var str = inStream.readString();
                        inStream.readPendingValues();
                        var c = cb.obj as C;
                        Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name +
                                                ", s.value=" + c.s.value);
                    }
                    else if(line.Equals("9"))
                    {
                        //
                        // Invoke operation.
                        //
                        if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Expected exception");
                            continue;
                        }

                        var inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        try
                        {
                            inStream.throwException();
                        }
                        catch(PrintFailure)
                        {
                            // Expected.
                        }
                        catch(Ice.UserException)
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                        inStream.endEncapsulation();
                    }
                    else if(line.Equals("s"))
                    {
                        obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams);
                    }
                    else if(line.Equals("x"))
                    {
                        // Nothing to do.
                    }
                    else if(line.Equals("?"))
                    {
                        menu();
                    }
                    else
                    {
                        Console.Error.WriteLine("unknown command `" + line + "'");
                        menu();
                    }
                }
                catch(Ice.LocalException ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }
            while(!line.Equals("x"));

            return 0;
        }
Ejemplo n.º 13
0
    public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
    {
        outParams = null;

        var communicator = current.adapter.getCommunicator();

        Ice.InputStream inStream = null;
        if(inParams.Length > 0)
        {
            inStream = new Ice.InputStream(communicator, inParams);
            inStream.startEncapsulation();
        }

        if(current.operation.Equals("printString"))
        {
            var message = inStream.readString();
            inStream.endEncapsulation();
            Console.WriteLine("Printing string `" + message + "'");
            return true;
        }
        else if(current.operation.Equals("printStringSequence"))
        {
            var seq = StringSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing string sequence {");
            for(int i = 0; i < seq.Length; ++i)
            {
                if(i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write("'" + seq[i] + "'");
            }
            Console.WriteLine("}");
            return true;
        }
        else if(current.operation.Equals("printDictionary"))
        {
            var dict = StringDictHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing dictionary {");
            bool first = true;
            foreach(var e in dict)
            {
                if(!first)
                {
                    Console.Write(", ");
                }
                first = false;
                Console.Write(e.Key + "=" + e.Value);
            }
            Console.WriteLine("}");
            return true;
        }
        else if(current.operation.Equals("printEnum"))
        {
            var c = ColorHelper.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing enum " + c);
            return true;
        }
        else if(current.operation.Equals("printStruct"))
        {
            var s = Structure.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value);
            return true;
        }
        else if(current.operation.Equals("printStructSequence"))
        {
            var seq = StructureSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing struct sequence: {");
            for(int i = 0; i < seq.Length; ++i)
            {
                if(i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write(seq[i].name + "=" + seq[i].value);
            }
            Console.WriteLine("}");
            return true;
        }
        else if(current.operation.Equals("printClass"))
        {
            var cb = new ReadValueCallback();
            inStream.readValue(cb.invoke);
            inStream.readPendingValues();
            inStream.endEncapsulation();
            var c = cb.obj as C;
            Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value);
            return true;
        }
        else if(current.operation.Equals("getValues"))
        {
            var c = new C(new Structure("green", Color.green));
            var outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeValue(c);
            outStream.writeString("hello");
            outStream.writePendingValues();
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return true;
        }
        else if(current.operation.Equals("throwPrintFailure"))
        {
            Console.WriteLine("Throwing PrintFailure");
            var ex = new PrintFailure("paper tray empty");
            var outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeException(ex);
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return false;
        }
        else if(current.operation.Equals("shutdown"))
        {
            current.adapter.getCommunicator().shutdown();
            return true;
        }
        else
        {
            throw new Ice.OperationNotExistException(current.id, current.facet, current.operation);
        }
    }