Esempio n. 1
0
        public void postMessage(UInt64 connID, BufferT msgBuff)
        {
            //auto f = connections.find(connID);
            //assert(f != connections.end());
            //auto & conn = f->second;
            ClientConnection conn = connections[connID];
            Debug.Assert(conn.ref_id_at_client == connID); // self-consistency
            BufferT buff = platform.makeBuffer();
            IPublishableComposer composer = platform.makePublishableComposer(buff);
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            mh.type = PublishableStateMessageHeader.MsgType.connectionMessage;
            mh.priority = 0; // TODO: source
            mh.state_type_id_or_direction = (UInt64)PublishableStateMessageHeader.ConnMsgDirection.toServer;
            Debug.Assert(conn.ref_id_at_client == connID);
            mh.ref_id_at_subscriber = conn.ref_id_at_client;
            Debug.Assert(conn.ref_id_at_server != 0);
            mh.ref_id_at_publisher = conn.ref_id_at_server;
            GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
            ReadIteratorT riter = msgBuff.getReadIterator();

            composer.appendRaw(riter);

            GMQueue.helperComposePublishableStateMessageEnd(composer);
            //assert(transport != nullptr);
            transport.postMessage(buff);
        }
        public static void writeVlqIntegral(BufferT buff, UInt64 val)
        {
            byte[] intTemp = new byte[10];

            int  ix      = 0;
            byte current = (byte)(val & 0x7f);

            val       >>= 7;
            intTemp[ix] = current;
            bool done = val == 0;

            while (!done)
            {
                current  = (byte)(val & 0x7f);
                current += 0x80;
                val    >>= 7;
                ++ix;
                intTemp[ix] = current;
                done        = val == 0;
            }

            while (ix != 0)
            {
                buff.appendUint8(intTemp[ix]);
                --ix;
            }
            buff.appendUint8(intTemp[0]);
        }
Esempio n. 3
0
 private static void ComposeMessageThree(BufferT buffer, mtest.struct_one msg)
 {
     mtest.test_json.composeMessage_message_three(buffer,
                                                  thirdParam: msg.thirdParam,
                                                  firstParam: msg.firstParam, fifthParam: msg.fifthParam, forthParam: msg.forthParam, seventhParam: msg.seventhParam,
                                                  eighthParam: msg.eighthParam,
                                                  ninethParam: msg.ninethParam,
                                                  secondParam: msg.secondParam,
                                                  tenthParam: msg.tenthParam,
                                                  sixthParam: msg.sixthParam
                                                  );
 }
        public static bool AreEqualIgnoreEol(BufferT left, BufferT right)
        {
            if (ReferenceEquals(left, right))
            {
                return(true);
            }
            else if (left == null)
            {
                return(false);
            }
            else if (right == null)
            {
                return(false);
            }

            ReadIteratorT l = left.getReadIterator();
            ReadIteratorT r = right.getReadIterator();

            while (l.isData() && r.isData())
            {
                // \r\n == \n
                if (l.getChar() == '\r' && r.getChar() == '\n')
                {
                    l.inc();
                    if (!l.isData() || l.getChar() != '\n')
                    {
                        return(false);
                    }
                }
                // \n == \r\n
                else if (l.getChar() == '\n' && r.getChar() == '\r')
                {
                    r.inc();
                    if (!r.isData() || r.getChar() != '\n')
                    {
                        return(false);
                    }
                }
                else if (l.getChar() != r.getChar())
                {
                    return(false);
                }

                l.inc();
                r.inc();
            }

            return(!l.isData() && !r.isData());
        }
 public static IPublishableComposer makePublishableComposer(Protocol proto, BufferT buffer)
 {
     if (proto == Protocol.Json)
     {
         return(new JsonPublishableComposer(buffer));
     }
     else if (proto == Protocol.Gmq)
     {
         return(new GmqPublishableComposer(buffer));
     }
     else
     {
         throw new Exception();
     }
 }
    public void onClientRequest(UInt64 connID, basic_test.scope_test_exchange.Icl_request rq, ConnectionInSCScope connection)
    {
        Console.Write("Client request (connID = {0}):\n", connID);
        Console.Write("     ordinal                : {0}\n", rq.ordinal);
        //		log::default_log::log( log::LogLevel::fatal, "     text                   : {}\n", rq.text );

        basic_test.scope_test_exchange.srv_response reply = new basic_test.scope_test_exchange.srv_response();
        reply.replied_on       = rq.ordinal;
        reply.value            = ++(connection.replyCtr);
        reply.text_from_server = String.Format("srv reply {0} -> {1}", rq.ordinal, reply.value);
        BufferT buff = Platform.makeBuffer();

        basic_test.scope_test_exchange.composeMessage_srv_response(
            buff, replied_on: reply.replied_on, value: reply.value,
            text_from_server: reply.text_from_server);
        connection.postMessage(buff);
    }
Esempio n. 7
0
 public void connect(UInt64 connID, string path)
 {
     ClientConnection conn = connections[connID];
     //assert(f != connections.end());
     //auto & conn = f->second;
     Debug.Assert(conn.ref_id_at_client == connID); // self-consistency
     BufferT buff = platform.makeBuffer();
     IPublishableComposer composer = platform.makePublishableComposer(buff);
     PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
     mh.type = PublishableStateMessageHeader.MsgType.connectionRequest;
     mh.priority = 0; // TODO: source
     mh.state_type_id_or_direction = (UInt64)PublishableStateMessageHeader.ConnMsgDirection.toServer;
     mh.path = path;
     Debug.Assert(conn.ref_id_at_client == connID);
     mh.ref_id_at_subscriber = conn.ref_id_at_client;
     GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
     GMQueue.helperComposePublishableStateMessageEnd(composer);
     transport.postMessage(buff);
     conn.connection.setRequestSent();
 }
Esempio n. 8
0
 public void subscribe(StateSubscriberBase subscriber, string path)
 {
     for (int i = 0; i < subscribers.Count; ++i)
         if (subscribers[i].subscriber == subscriber)
         {
             BufferT buff = platform.makeBuffer();
             IPublishableComposer composer = platform.makePublishableComposer(buff);
             PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
             mh.type = PublishableStateMessageHeader.MsgType.subscriptionRequest;
             mh.priority = 0; // TODO: source
             mh.state_type_id_or_direction = subscriber.stateTypeID();
             mh.path = path;
             Debug.Assert(subscribers[i].ref_id_at_subscriber == (ulong)i);
             mh.ref_id_at_subscriber = subscribers[i].ref_id_at_subscriber;
             GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
             GMQueue.helperComposePublishableStateMessageEnd(composer);
             //assert(transport != nullptr);
             transport.postMessage(buff);
             return;
         }
     Debug.Assert(false); // not found
 }
 public static ThreadQueueItem makeGlobalMq(BufferT msg, int recipientID)
 {
     return(new ThreadQueueItem(msg, ThreadQueueItemType.GlobalMQ, recipientID));
 }
 public GmqPublishableComposer(BufferT buffer)
 {
     composer = new GmqComposer(buffer);
 }
 public GmqComposer(BufferT buff_)
 {
     buff = buff_;
 }
 public bool AreEqual(BufferT left, BufferT right)
 {
     return(SimpleBuffer.AreEqual(left, right));
 }
Esempio n. 13
0
 public virtual void postMessage(BufferT msg)
 {
     Debug.Assert(idx.isInitialized());
     gmq.postMessage(msg, id, idx);
 }
Esempio n. 14
0
        public void onMessage(IPublishableParser parser)
        {
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            GMQueue.helperParsePublishableStateMessageBegin(parser, ref mh);
            switch (mh.type)
            {
                case PublishableStateMessageHeader.MsgType.connectionRequest:
                    {
                        GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
                        pc.type = PublishableStateMessageHeader.MsgType.connectionRequest;
                        bool pathOK = GmqPathHelper.parse(mh.path, pc);
                        if (!pathOK)
                            throw new Exception(); // TODO: ... (bad path)

                        //auto f = connFactories.find(pc.statePublisherOrConnectionType);
                        //if (f == connFactories.end())
                        //	throw std::exception(); // TODO:  ... (no factory for conn name)
                        //auto & connFactory = *f->second;
                        IConnectionFactory connFactory = connFactories[pc.statePublisherOrConnectionType];

                        ServerConnection sc = new ServerConnection();
                        sc.connection = connFactory.create();
                        sc.ref_id_at_client = mh.ref_id_at_subscriber;
                        sc.ref_id_at_server = ++connIdxBase;
                        //sc.connection->pool = this;
                        //sc.connection->connID = sc.ref_id_at_server;
                        //sc.connection->status = ConnectionT::Status::connected;
                        sc.connection.setServerConnected(this, sc.ref_id_at_server);
                        /*auto ins = */
                        connections.Add(sc.ref_id_at_server, sc);
                        //assert(ins.second);

                        PublishableStateMessageHeader hdrBack = new PublishableStateMessageHeader();
                        hdrBack.type = PublishableStateMessageHeader.MsgType.connectionAccepted;
                        hdrBack.state_type_id_or_direction = (ulong)PublishableStateMessageHeader.ConnMsgDirection.toClient;
                        hdrBack.priority = mh.priority; // TODO: source?
                        hdrBack.ref_id_at_subscriber = mh.ref_id_at_subscriber;
                        hdrBack.ref_id_at_publisher = sc.ref_id_at_server;

                        BufferT msgBack = platform.makeBuffer();
                        IPublishableComposer composer = platform.makePublishableComposer(msgBack);
                        GMQueue.helperComposePublishableStateMessageBegin(composer, hdrBack);
                        GMQueue.helperComposePublishableStateMessageEnd(composer);
                        //assert(transport != nullptr);
                        transport.postMessage(msgBack);

                        break;
                    }
                case PublishableStateMessageHeader.MsgType.connectionMessage:
                    {
                        Debug.Assert(mh.state_type_id_or_direction == (ulong)PublishableStateMessageHeader.ConnMsgDirection.toServer);
                        //auto f = connections.find(mh.ref_id_at_publisher);
                        //if (f == connections.end())
                        //	throw std::exception();
                        //auto & conn = f->second;
                        ServerConnection conn = connections[mh.ref_id_at_publisher];
                        Debug.Assert(conn.ref_id_at_server == mh.ref_id_at_publisher); // self-consistency
                                                                                       //auto riter = parser.getIterator();
                        conn.connection.onMessage(parser.getIterator());
                        //parser = riter;
                        break;
                    }
                default:
                    throw new Exception(); // TODO: ... (unknown msg type)
            }
            GMQueue.helperParsePublishableStateMessageEnd(parser);
        }
Esempio n. 15
0
 public void postMessage(BufferT buff)
 {
     Debug.Assert(isConnected());
     //assert(pool != nullptr);
     pool.postMessage(connID, buff);
 }
Esempio n. 16
0
 public Buffer(BufferT parent)
 {
     this.parent = parent;
 }
Esempio n. 17
0
 public void onMessage(BufferT buffer)
 {
     ReadIteratorT riter = buffer.getReadIterator();
     IPublishableParser parser = platform.makePublishableParser(riter);
     onMessage(parser);
 }
 public JsonComposer(BufferT buff_)
 {
     buff = buff_;
 }
 public void postMessage(BufferT msg)
 {
     msgQueue.push_back(ThreadQueueItem.makeGlobalMq(msg, recipientID));
 }
 public ThreadQueueItem(BufferT msg_, ThreadQueueItemType msgType_, int recipientID_)
 {
     this.msg         = msg_;
     this.msgType     = msgType_;
     this.recipientID = recipientID_;
 }
 public JsonPublishableComposer(BufferT buffer)
 {
     composer = new JsonComposer(buffer);
 }