Esempio n. 1
0
File: K3p.cs Progetto: tmbx/kwm-ng
        /// <summary>
        /// Write the K3P message to the stream specified. This is done using
        /// reflection.
        /// </summary>
        public void ToStream(BinaryWriter w)
        {
            K3pCmd cmd = this as K3pCmd;

            if (cmd != null)
            {
                WriteInst(w, cmd.InputIns);
            }

            // When this class derives from K3pCmd, the instruction from K3pCmd
            // is encountered last. We must skip it.
            FieldInfo[] info = this.GetType().GetFields();
            for (int i = 0; i < ((cmd == null) ? info.Length : info.Length - 1); i++)
            {
                FieldInfo fi = info[i];
                try
                {
                    object value = fi.GetValue(this);
                    InternalToStream(w, value);
                }
                catch (Exception e)
                {
                    throw new K3pException("Cannot convert " + this.GetType().FullName + "." + fi.Name + " in binary", e);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Submit a query to the broker specified. The command array must
 /// contain at least one command, the last of which being the command
 /// having an associated result. A session will be created to handle
 /// the commands. The callback function specified will be called when
 /// the results are available.
 /// </summary>
 public void Submit(WmKmodBroker broker, K3pCmd[] inCmdArray, KmodQueryDelegate callback)
 {
     Debug.Assert(inCmdArray.Length > 0);
     InCmdArray   = inCmdArray;
     InCmdWithRes = InCmdArray[InCmdArray.Length - 1];
     Callback     = callback;
     base.Submit(broker);
 }
Esempio n. 3
0
File: K3p.cs Progetto: tmbx/kwm-ng
        /// <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);
        }
Esempio n. 4
0
 /// <summary>
 /// Submit a query to the broker specified. The command array must
 /// contain at least one command, the last of which being the command
 /// having an associated result. A session will be created to handle
 /// the commands. The callback function specified will be called when
 /// the results are available.
 /// </summary>
 public void Submit(WmKmodBroker broker, K3pCmd[] inCmdArray, KmodQueryDelegate callback)
 {
     Debug.Assert(inCmdArray.Length > 0);
     InCmdArray = inCmdArray;
     InCmdWithRes = InCmdArray[InCmdArray.Length - 1];
     Callback = callback;
     base.Submit(broker);
 }
Esempio n. 5
0
File: K3p.cs Progetto: tmbx/kwm-ng
        /// <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);
            }
        }