⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otamessageslistener.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
字号:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.funambol.mailclient.ui.controller;

import com.funambol.mailclient.config.MailClientConfig;
import com.funambol.mailclient.sm.SyncClient;
import com.funambol.syncml.client.MessageParserException;
import com.funambol.util.Log;
import com.funambol.util.ThreadPool;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.wireless.messaging.*;


/**
 * Listener for OTA Messages. Delegates to the Message Handler class
 * the ability to handle OTA configuration messages and
 * Server Alert Notification messages
 */
public class OTAMessagesListener implements MessageListener, Runnable {
    
    private MessageConnection smsconn;
    private String smsConnection;
    
    public static boolean smsHandling;
    public static boolean syncViaSMS;
    public static boolean startViaOTA;
    public static boolean firstSMS = true;
    
    /** Creates a new instance of OTAMessagesListener */
    public OTAMessagesListener(String smsPort) {
        smsConnection = "sms://:" + smsPort;
    }
    
    /**
     * Opens the connection and registers this listener
     */
    public void init() {
        if (smsconn == null) {
            try {
                smsconn = (MessageConnection)Connector.open(smsConnection);
                smsconn.setMessageListener(this);
            } catch (IOException ioe) {
                ioe.printStackTrace();
                Log.error(this, "IOException opening smsConnection " +
                        "or setting message listener");
            }
        }
    }
    
    public void setConnection(MessageConnection mc) throws IOException {
        this.smsconn = mc;
        smsconn.setMessageListener(this);
    }
    
    /**
     * Callback Method invoked when an SMS is received on a specific port
     */
    public void notifyIncomingMessage(MessageConnection messageConnection) {
        Log.info("notifyIncomingMessage invoked");
        Log.info("SyncClient.isBusy(): " + SyncClient.isBusy());
        Log.info("smsHandling: " + smsHandling);
        if ( (SyncClient.isBusy()) || (smsHandling) ) {
            Log.info("Sync in progress: SMS ignored.");
        } else {
            smsHandling = true;
            if(!startViaOTA){
                syncViaSMS = true;
            }else{
                startViaOTA = false;
            }
            UIController.getThreadPool().startThread(this);
        }
    }
    
    /**
     * Fired in a separated thread by notifyIncomingMessage() when a binary SMS
     * is received
     */
    public void run() {
        Log.info("Message receiving");
        try {
            Message msg = smsconn.receive();
            if (msg != null) {
                MessageHandler messageHandler = new MessageHandler();
                messageHandler.handleMessage(msg);
            }
        } catch (MessageParserException e) {
            Log.error("Error: " + e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            Log.error("Error: " + e.toString());
            e.printStackTrace();
        }  finally {
            OTAMessagesListener.smsHandling = false;
        }
    }
    
    public void close() throws IOException {
        if (smsconn!= null) {
            smsconn.close();
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -