libStatGen Software  1
PhoneHome.h
00001 /*
00002  *  Copyright (C) 2013  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __PHONEHOME_H__
00019 #define __PHONEHOME_H__
00020 
00021 #include <string>
00022 #include "StringBasics.h"
00023 
00024 
00025 // By default, CompletionStatus PhoneHome is disabled.
00026 // To enable it:
00027 //    1) call "enableCompletionStatus"
00028 //    2) call checkVersion
00029 //    3) call completionStatus with the program name passed in
00030 //      
00031 class PhoneHome
00032 {
00033 public:
00034     // Public method that can be set to control the thinning of version checks.
00035     static int allThinning;
00036 
00037     // Enable Completion Status PhoneHome, it is disabled by default.
00038     // It can also be enabled by:
00039     //    * calling checkVersion
00040     //    * calling completionStatus with the program name passed in
00041     // Program name must be specified in order to log completionStatus
00042     static void enableCompletionStatus(const char* programName = NULL);
00043     
00044     // Disable Completion Status PhoneHome. (It is already disabled by default.)
00045     static void disableCompletionStatus();
00046 
00047     // Check the version, printing a message if a newer version is available.
00048     // Enables CompletionStatus PhoneHome
00049     // Returns false if there is a new version available, otherwise true.
00050     static bool checkVersion(const char* programName,
00051                              const char* version,
00052                              const char* params = NULL);
00053 
00054     // If completionStatus is enabled, send the completion status.
00055     // completionStatus is enabled if:
00056     //     1) enableCompletionStatus was called
00057     //     2) checkVersion was called
00058     //     3) programName is passed in
00059     // ProgramName is ignored if it has previously been set.
00060     static void completionStatus(const char* status,
00061                                  const char* programName = NULL);
00062 
00063     static void setURL(const char* url);
00064     static void resetURL();
00065 
00066 protected:
00067 private:
00068     static void add(const char* name, const char* val);
00069     static bool connect();
00070 
00071     static bool ourEnableCompletionStatus;
00072     static std::string ourBaseURL;
00073     static std::string ourURL;
00074     static char ourPrefixChar;
00075     static int ourNumber;
00076     static String ourToolName;
00077 
00078     static String ourReturnString;
00079 };
00080 
00081 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends