updater.h

来自「funambol window mobile客户端源代码」· C头文件 代码 · 共 223 行

H
223
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission 
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * 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 Affero General Public License 
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably 
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#ifndef INCL_UPDATER
#define INCL_UPDATER
    
#include <string>
#include <list>
#include "UpdateParams.h"
#include "pim/ClientSettings.h"

using namespace std;

#define UP_URL_RESOURCE     "/updateserver/update" // "/funambol/update"
#define UP_URL_COMPONENT    "component="
#define UP_URL_VERSION      "version="

/**
 * This class is responsible to handle the update procedure of the client.
 * It contains all the action that has to be done in order to handle the udpate.
 * 
 */
__declspec(dllexport) class Updater {
  
private:
    
    static Updater* pinstance;

    string component;
    string version;
    
    HWND uiHwnd;
     /**
    * Values that comes from the current time and are added to the current
    * values in the registry
    *
    * currentHttpIntervalTime = lastCheckUpdate * intervalCheckUpdateHttp
    * currentRemindTime       = lastCheckUpdate * intervalRemind
    *
    */
    unsigned long currentTime;
    unsigned long currentHttpIntervalTime;
    unsigned long currentRemindTime;

    /**
    * Pointer to the ClientSettings singleton
    */
    ClientSettings* settings;
    
    /**    
    * The UpdateParams object is in the ClientSettings class and it is used
    * by this class through the ClientSettings.
    */
    UpdateParams& params;
    
    /**
    * It checks if it is needed to check via url or locally only.
    * If locally only, there is no other stuff to do. Otherwise the data
    * are overwritten in the UpdateParams and then written in the registry.
    */
    int requestUpdate();
    
    /**
    * Used to ask the server. Parse the message from the server and populate 
    * the UpdateParams class.
    */
    int parseMessage(string message);
    
    /**
    * Used to ask the server. Send the message from the server and populate 
    * the UpdateParams class.
    */
    int sendMessage(const char* message);
       
    
    /**
    * It populate all the times that are needed to make the check to start the update process.    
    */
    int populateTime();
    
    /**
    * launch the whole update procedure.
    */
    bool launchUpdateProcess();

    
    /**
    * utility to convert an unsigned long into a string
    */
    string long2string(unsigned long v) ;
    
    /**
    * utility to convert a string into an unsigned long
    */
    unsigned long string2long(string v) ;

public:
    
    __declspec(dllexport) static Updater* getInstance(const char* comp, HWND hwnd, ClientSettings* cs);

     Updater(const char* component, HWND hwnd, ClientSettings* cs);
    
     ~Updater();

    /**
    * It starts all the update procedure process. It leads the update algorithm.
    * it return 0,-1 if there is no update
    * return 1,2 if there is an update
    */
    int start();
    
    /**
    * It starts manually all the update procedure process. it force to check the 
    * it return 0 if there is no update
    * return 1 if there is an update
    */
    int startManually();

    /**
    * It stores the Params into the registry. they are used next times to be
    * return 0 if all ok. It uses the ClientSettings class to store them.
    */
    int storeParams();
            
    /**
    * Return the params
    * It returns 0
    */
    int readParams();
    
    /**
    * check the field mandatory in the map. If there is any and its value is 1 it returns true,
    * return false othewise.
    */
    bool isMandatory();
            
    /**
    * Change the flag mandatory in class to be stored in the registry
    */
    void setMandatory(string mandatory);
    
    /**
    * Check if the current update has to be showed to the user. If not, exit.
    * The time is configurable (default 2h)
    */
    bool isToNotify();

    /**
    * Set the current time after that the last check was done. 
    * Used to be stored in the registry to check the if the latest time and the current time
    * are greater then the interval set
    */
    void setCurrentTime(string currentTime);                
                                                            
    /**
    * It needs to show messages to the user using a type and using the 
    * params stored in the class.
    */                                        
    int showMessage(int type);

    /**
    * Check the update from the server to see if there is a new client available
    */
    int checkUpdateFromServer();

    /**
    * check the update on the server. If it is necessary set a value to 1
    * return  0 if there is no action to do
    * return  1 if there is something to download
    */
    int checkIsToUpdate();
    
    /**
    * it calls the checkIsToUpdate to discover if there is an update
    * it calls start to continue the whole process
    */
    int startWithoutUI();

    /**
    * used to store the time 
    */
    void updateTime();
    
};                         

// get the ClientSettings object
__declspec(dllexport) Updater* getUpdater(const char* comp, HWND hwnd, ClientSettings* cs);

#endif

⌨️ 快捷键说明

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