基于xulrunner架构下的Observer Mode

当用户选择操作设备的动作后,主要是UI层的操作,比如购买车票,选择票数等动作,都会触发驱动程序给设备发送指令,当设备执行命令后会给

驱动层反馈执行结果。但是UI层什么知道结果呢,因为急于xulrunner的架构,js+xul出于UI层,只是通过组建接口进行通信。所以UI层采用观察者模式

观察驱动层发出的指定注册后的消息。当有消息反馈时,做出相应的反馈。

 

以下是观察者注册监听消息的代码片段

/********************************************
                  定义消息
********************************************/
var Accobserver =
{
    QueryInterface: function(iid)
    {
      if(iid.equals(Components.interfaces.nsISupports) || iid.equals(Components.interfaces.nsIObserver))
      return this;
      throw Components.results.NS_ERROR_NO_INTERFACE;
    },

    observe: function(subject, topic, data)
    { 
      if(topic=="timer-callback")
      { 
               
      }    
      if(topic=="EQUMSG_CHECKCARDNOW")             //验卡消息
      {
         WriteLog("收到验卡消息");
      }

     if(topic=="EQUMSG_CARDREADOK")        //读卡消息
     {  
        //WriteLog("UI:收到读卡成功消息");
     } 
     if(topic=="EQUMSG_IO_CARDPOS_ARRIVE")
     {
      
     }
     if(topic=="inmoney")
      {   
          InMoneyProcess();
      }  
     if(topic=="EQUMSG_CARDREADFAIL")
     {                      
       }   
      if(topic == "EQUMSG_WORKMODECHANGE")
      {  
        LogStr = "主界面收到消息("+topic+")";
          WriteLog(LogStr);
          if(G_MapOriginal==1)
          {
         G_WorkMode=GetWorkMode(); 
         WorkModeShow(G_WorkMode);    
        }    
      }  
      if(topic == "EQUMSG_CD_ADDVALUEOK")
      {  
           
      }  
      if(topic == "EQUMSG_IO_CARDPOS_LEAVE")
      {  
         
      }      
      if(topic == "EQUMSG_CARDINLIST")                  //退币
      {   

      }
      if(topic == "EQUMSG_KB_PWIN")                     //密码输入
      {  
       
      }
      if(topic == "EQUMSG_BC_CARDREADOK")               //读银行卡成功
      {  
       
      }
      if(topic == "EQUMSG_IO_CARDLOCK_UN")               //闸口打开成功
      {     
         
      }
      if(topic == "EQUMSG_CANCEL")                      //取消
      {  
           MapCancel();
      }
     if(topic == "EQUMSG_IO_BACKDOOR_OPEN")
     {
        B_CloseDoor=1;
        G_Retvalue=GetValue(IsInMaintenance);  
        if(G_Retvalue==0&&G_MapOriginal==1)
          {
           openmaintance(1);
        } 
     }
     if(topic == "EQUMSG_IO_BACKDOOR_CLOSE")
     {
       B_CloseDoor=0;
       G_Retvalue = GetValue(IsInMaintenance);
       if(G_Retvalue == 0)
       {
         G_Retvalue=ExitMantance();
         if(G_Retvalue< 50)
         {
              equipment_maintenance(false);
            }
        }
     }     
     if(topic == "Refunded")
     {
      
     }
     if(topic == "BM_Process")       
     {
       
     }
     if(topic == "BM_WorkAck"||topic == "BM_Valid")
     {
      
     }
     if(topic == "outticketfinish")    //出票完成
     {
         OutTicketFinish();
     }
     if(topic == "outticketfail")      //出票失败
     {
        BackTomian();
       WorkModeShow(57);  
     }
   
     if(topic == "EQUMSG_EXITPROG")    //退出程序 
     {
         LogStr = "主界面收到消息("+topic+")";
           WriteLog(LogStr);
         Exitprog();
     }
   },
 register: function()
 {  
                var observerService = Components.classes["@mozilla.org/observer-service;1"]
               .getService(Components.interfaces.nsIObserverService); 
                observerService.addObserver(this, "timer-callback", false);
                observerService.addObserver(this, "inmoney", false);
                observerService.addObserver(this, "outticketfinish", false);
                observerService.addObserver(this, "EQUMSG_CHECKCARDNOW", false); 
                observerService.addObserver(this, "EQUMSG_CD_ADDVALUEOK", false);
                observerService.addObserver(this, "EQUMSG_CARDREADOK", false);
                observerService.addObserver(this, "EQUMSG_CARDREADFAIL", false);               
               observerService.addObserver(this, "EQUMSG_CANCEL", false); 
               observerService.addObserver(this, "EQUMSG_IO_CARDPOS_ARRIVE", false); 
              observerService.addObserver(this, "EQUMSG_IO_CARDPOS_LEAVE", false); 
              observerService.addObserver(this, "EQUMSG_BC_CARDREADOK", false);   
              observerService.addObserver(this, "EQUMSG_WORKMODECHANGE", false);       
              observerService.addObserver(this, "EQUMSG_BC_SUBVALUEOK", false); 
              observerService.addObserver(this, "EQUMSG_BC_SUBVALUEFAIL", false); 
              observerService.addObserver(this, "EQUMSG_KB_PWIN", false); 
              observerService.addObserver(this, "EQUMSG_CD_ADDVALUEFAIL", false); 
              observerService.addObserver(this, "Refunded", false); 
              observerService.addObserver(this, "EQUMSG_CARDINLIST", false); 
              observerService.addObserver(this, "EQUMSG_IO_CARDINSERT_UN", false);
              observerService.addObserver(this, "EQUMSG_IO_BACKDOOR_OPEN", false);
              observerService.addObserver(this, "EQUMSG_IO_BACKDOOR_CLOSE", false);  
              observerService.addObserver(this, "EQUMSG_IO_CARDLOCK_UN", false); 
           observerService.addObserver(this, "BM_Process", false); 
               observerService.addObserver(this, "BM_WorkAck", false);
              observerService.addObserver(this, "BM_Valid", false);
              observerService.addObserver(this, "outticketfail", false);
              observerService.addObserver(this, "EQUMSG_EXITPROG", false);
             
  },  
 unregister: function()
 {
                var observerService = Components.classes["@mozilla.org/observer-service;1"]
                .getService(Components.interfaces.nsIObserverService);
                observerService.removeObserver(this, "timer-callback");  
                observerService.removeObserver(this, "inmoney");
                observerService.removeObserver(this, "outticketfinish");
                observerService.removeObserver(this, "EQUMSG_CHECKCARDNOW");
                observerService.removeObserver(this, "EQUMSG_CD_ADDVALUEOK"); 
                observerService.removeObserver(this, "EQUMSG_CARDREADOK");
                observerService.removeObserver(this, "EQUMSG_CARDREADFAIL");             
              observerService.removeObserver(this, "EQUMSG_CANCEL");
              observerService.removeObserver(this, "EQUMSG_IO_CARDPOS_ARRIVE");
              observerService.removeObserver(this, "EQUMSG_IO_CARDPOS_LEAVE");
              observerService.removeObserver(this, "EQUMSG_BC_CARDREADOK");
              observerService.removeObserver(this, "EQUMSG_WORKMODECHANGE");
              observerService.removeObserver(this, "EQUMSG_BC_SUBVALUEOK");
              observerService.removeObserver(this, "EQUMSG_BC_SUBVALUEFAIL");
              observerService.removeObserver(this, "EQUMSG_KB_PWIN");
              observerService.removeObserver(this, "EQUMSG_CD_ADDVALUEFAIL");
              observerService.removeObserver(this, "Refunded");
              observerService.removeObserver(this, "EQUMSG_CARDINLIST");
              observerService.removeObserver(this, "EQUMSG_IO_CARDINSERT_UN");
              observerService.removeObserver(this, "EQUMSG_IO_BACKDOOR_OPEN");
              observerService.removeObserver(this, "EQUMSG_IO_BACKDOOR_CLOSE");
              observerService.removeObserver(this, "EQUMSG_IO_CARDLOCK_UN");
           observerService.removeObserver(this, "BM_Process");
               observerService.removeObserver(this, "BM_WorkAck");
               observerService.removeObserver(this, "BM_Valid");  
               observerService.removeObserver(this, "outticketfail");  
               observerService.removeObserver(this, "EQUMSG_EXITPROG");           
  }  
};

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值