Beispiel #1
0
        public void sendMsg(K3pMsg msg)
        {
            outState = OutState.Sending;
            MemoryStream s = new MemoryStream();

            msg.ToStream(s);
            outBuf = s.ToArray();
            outPos = 0;
        }
Beispiel #2
0
        public void PostTransactionCommand(KmodTransaction transaction, K3pMsg msg, bool haveResultFlag)
        {
            Debug.Assert(transaction == m_curTransaction);
            Debug.Assert(IsTransactionExecuting());
            Debug.Assert(IsThreadReadyForUserCommand());
            KmodThreadCommand cmd = new KmodThreadCommand(m_curThread, msg, haveResultFlag);

            m_curThread.PostToWorker(cmd);
            m_curCommand = haveResultFlag ? cmd : null;
        }
Beispiel #3
0
        /// <summary>
        /// Return the value of the K3P message field specified.
        /// </summary>
        private Object InternalFromElementReader(K3pElementReader r, Type t)
        {
            if (t == typeof(UInt32))
            {
                return(r.Int());
            }
            else if (t.IsEnum)
            {
                return(Enum.ToObject(t, r.Int()));
            }
            else if (t == typeof(String))
            {
                return(r.Str());
            }
            else if (t == typeof(byte[]))
            {
                return(r.Bin());
            }

            else if (t.IsArray)
            {
                Type   elType = t.GetElementType();
                UInt32 size   = r.Int();
                Array  a      = Array.CreateInstance(elType, size);
                for (UInt32 i = 0; i < size; i++)
                {
                    a.SetValue(InternalFromElementReader(r, elType), i);
                }
                return(a);
            }

            else if (t.IsSubclassOf(typeof(K3pMsg)))
            {
                K3pMsg m = (K3pMsg)Activator.CreateInstance(t);
                m.FromElementReader(r);
                return(m);
            }

            else
            {
                throw new K3pException("unsupported type " + t.FullName + " in K3P");
            }
        }
Beispiel #4
0
 public KmodThreadCommand(KmodThread thread, K3pMsg msg, bool haveResultFlag)
 {
     m_thread = thread;
     Msg = msg;
     HaveResultFlag = haveResultFlag;
 }
Beispiel #5
0
 public void sendMsg(K3pMsg msg)
 {
     outState = OutState.Sending;
     MemoryStream s = new MemoryStream();
     msg.ToStream(s);
     outBuf = s.ToArray();
     outPos = 0;
 }
Beispiel #6
0
 /// <summary>
 /// Send the next command to KMOD.
 /// </summary>
 public void PostCommand(K3pMsg msg, bool haveResultFlag)
 {
     Broker.PostTransactionCommand(this, msg, haveResultFlag);
 }
Beispiel #7
0
 /// <summary>
 /// Helper method for Slurp().
 /// </summary>
 private void SlurpHelper(K3pMsg inMsg, out K3pMsg outMsg)
 {
     inMsg.FromElementReader(this);
     outMsg = inMsg;
 }
Beispiel #8
0
        /// <summary>
        /// Slurp a result according to the input command specified. The method
        /// throws an exception if it cannot slurp a valid result. The method 
        /// sets outDesc to a string describing the result obtained and outMsg
        /// to the result obtained.
        /// </summary>
        public void Slurp(K3pCmd inCmd, out String outDesc, out K3pMsg outMsg)
        {
            outDesc = "unexpected result";
            UInt32 outputIns = Ins();

            if (outputIns == K3p.KMO_INVALID_REQ)
                throw new Exception("invalid request");

            else if (outputIns == K3p.KMO_INVALID_CONFIG)
            {
                outMsg = new K3p.kmo_invalid_config();
                outDesc = "invalid configuration";
            }

            else if (outputIns == K3p.KMO_SERVER_ERROR)
            {
                K3p.kmo_server_error m = new K3p.kmo_server_error();
                SlurpHelper(m, out outMsg);
                outDesc = "cannot contact ";
                String name = "server";
                if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_KPS) name = "KPS";
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_OPS) name = "OPS";
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_OUS) name = "OUS";
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_OTS) name = "OTS";
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_IKS) name = "IKS";
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_EKS) name = "EKS";
                outDesc += name + ": ";
                String reason = m.message;
                if (m.error == K3p.kmo_server_error.Kmo_Serror.KMO_SERROR_TIMEOUT)
                    reason = "timeout occurred";
                else if (m.error == K3p.kmo_server_error.Kmo_Serror.KMO_SERROR_UNREACHABLE)
                    reason = "host unreachable";
                outDesc += reason;
            }

            else if (outputIns == K3p.KMO_MUST_UPGRADE)
            {
                K3p.kmo_must_upgrade m = new K3p.kmo_must_upgrade();
                SlurpHelper(m, out outMsg);
                outDesc = "must upgrade ";
                String what = "plugin";
                if (m.what == K3p.KMO_UPGRADE_KPS) what = "KPS";
                outDesc += what;
            }

            else if (outputIns == K3p.KMO_SERVER_INFO_ACK)
                SlurpHelper(new K3p.kmo_server_info_ack(), out outMsg);

            else if (outputIns == K3p.KMO_SERVER_INFO_NACK)
                SlurpHelper(new K3p.kmo_server_info_nack(), out outMsg);

            else if (inCmd is K3p.kpp_get_kws_ticket && outputIns == 0)
                SlurpHelper(new K3p.kmo_get_kws_ticket(), out outMsg);

            else if (inCmd is K3p.kpp_lookup_rec_addr && outputIns == 0)
                SlurpHelper(new K3p.kmo_lookup_rec_addr(), out outMsg);

            else
                throw new Exception("unexpected KMOD instruction " + outputIns);
        }
Beispiel #9
0
 public KmodThreadCommand(KmodThread thread, K3pMsg msg, bool haveResultFlag)
 {
     m_thread       = thread;
     Msg            = msg;
     HaveResultFlag = haveResultFlag;
 }
Beispiel #10
0
 public void PostTransactionCommand(KmodTransaction transaction, K3pMsg msg, bool haveResultFlag)
 {
     Debug.Assert(transaction == m_curTransaction);
     Debug.Assert(IsTransactionExecuting());
     Debug.Assert(IsThreadReadyForUserCommand());
     KmodThreadCommand cmd = new KmodThreadCommand(m_curThread, msg, haveResultFlag);
     m_curThread.PostToWorker(cmd);
     m_curCommand = haveResultFlag ? cmd : null;
 }
Beispiel #11
0
 /// <summary>
 /// Send the next command to KMOD.
 /// </summary>
 public void PostCommand(K3pMsg msg, bool haveResultFlag)
 {
     Broker.PostTransactionCommand(this, msg, haveResultFlag);
 }
Beispiel #12
0
 /// <summary>
 /// Helper method for Slurp().
 /// </summary>
 private void SlurpHelper(K3pMsg inMsg, out K3pMsg outMsg)
 {
     inMsg.FromElementReader(this);
     outMsg = inMsg;
 }
Beispiel #13
0
        /// <summary>
        /// Slurp a result according to the input command specified. The method
        /// throws an exception if it cannot slurp a valid result. The method
        /// sets outDesc to a string describing the result obtained and outMsg
        /// to the result obtained.
        /// </summary>
        public void Slurp(K3pCmd inCmd, out String outDesc, out K3pMsg outMsg)
        {
            outDesc = "unexpected result";
            UInt32 outputIns = Ins();

            if (outputIns == K3p.KMO_INVALID_REQ)
            {
                throw new Exception("invalid request");
            }

            else if (outputIns == K3p.KMO_INVALID_CONFIG)
            {
                outMsg  = new K3p.kmo_invalid_config();
                outDesc = "invalid configuration";
            }

            else if (outputIns == K3p.KMO_SERVER_ERROR)
            {
                K3p.kmo_server_error m = new K3p.kmo_server_error();
                SlurpHelper(m, out outMsg);
                outDesc = "cannot contact ";
                String name = "server";
                if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_KPS)
                {
                    name = "KPS";
                }
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_OPS)
                {
                    name = "OPS";
                }
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_OUS)
                {
                    name = "OUS";
                }
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_OTS)
                {
                    name = "OTS";
                }
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_IKS)
                {
                    name = "IKS";
                }
                else if (m.sid == K3p.kmo_server_error.Kmo_Sid.KMO_SID_EKS)
                {
                    name = "EKS";
                }
                outDesc += name + ": ";
                String reason = m.message;
                if (m.error == K3p.kmo_server_error.Kmo_Serror.KMO_SERROR_TIMEOUT)
                {
                    reason = "timeout occurred";
                }
                else if (m.error == K3p.kmo_server_error.Kmo_Serror.KMO_SERROR_UNREACHABLE)
                {
                    reason = "host unreachable";
                }
                outDesc += reason;
            }

            else if (outputIns == K3p.KMO_MUST_UPGRADE)
            {
                K3p.kmo_must_upgrade m = new K3p.kmo_must_upgrade();
                SlurpHelper(m, out outMsg);
                outDesc = "must upgrade ";
                String what = "plugin";
                if (m.what == K3p.KMO_UPGRADE_KPS)
                {
                    what = "KPS";
                }
                outDesc += what;
            }

            else if (outputIns == K3p.KMO_SERVER_INFO_ACK)
            {
                SlurpHelper(new K3p.kmo_server_info_ack(), out outMsg);
            }

            else if (outputIns == K3p.KMO_SERVER_INFO_NACK)
            {
                SlurpHelper(new K3p.kmo_server_info_nack(), out outMsg);
            }

            else if (inCmd is K3p.kpp_get_kws_ticket && outputIns == 0)
            {
                SlurpHelper(new K3p.kmo_get_kws_ticket(), out outMsg);
            }

            else if (inCmd is K3p.kpp_lookup_rec_addr && outputIns == 0)
            {
                SlurpHelper(new K3p.kmo_lookup_rec_addr(), out outMsg);
            }

            else
            {
                throw new Exception("unexpected KMOD instruction " + outputIns);
            }
        }