My Project
AutoUpdaterClient.h
1 #pragma once
2 
3 #ifdef WIN32
4 # ifndef _CRT_SECURE_NO_WARNINGS
5 # define _CRT_SECURE_NO_WARNINGS
6 # endif
7 #endif
8 
9 #include <tchar.h>
10 #include <string>
11 #include <queue>
12 
13 // ParaEngine includes
14 #include "PluginAPI.h"
15 #include "PluginLoader.hpp"
16 
17 // ParaEngine interfaces that we use
18 #include "INPL.h"
19 #include "INPLRuntime.h"
20 #include "IParaEngineCore.h"
21 #include "IParaEngineApp.h"
22 
23 #include "NPLInterface.hpp"
24 
25 #include "util/Mutex.hpp"
26 #include "util/Semaphore.hpp"
27 
28 namespace NPL
29 {
32  {
33  public:
36  {
37  AUP_NOT_STARTED,
38  AUP_STARTED,
39  AUP_NOCHANGE,
40  AUP_UNKNOWN,
41  AUP_BROKENFILE,
42  AUP_ERROR,
43  AUP_PROGRESS,
44  // apply patch completed
45  AUP_COMPLETED,
46  // info host to apply patch.
47  AUP_DO_APPLY_PATCH,
48  };
51  {
52  ProgressMessage():m_eventType(AUP_NOT_STARTED),m_finishcount(0), m_allcount(0) {};
53  ProgressMessage(AutoUpdaterProgress eventType, const char* msg=NULL, int finishcount=0, int allcount=0)
54  :m_eventType(eventType),m_finishcount(finishcount), m_allcount(allcount)
55  {
56  if(msg)
57  m_msg = msg;
58  };
59  AutoUpdaterProgress m_eventType;
60  std::string m_msg;
61  int m_finishcount;
62  int m_allcount;
63  };
64 
67  {
68  public:
69  virtual void OnProgress(const ProgressMessage& msg) = 0;
70  };
71 
75  virtual void SetUpdaterDllPath(const char* sDllPath = NULL) = 0;
76 
80  virtual void OnProgress(AutoUpdaterProgress eventType, const char* msg=NULL, int finishcount=0, int allcount=0) = 0;
81 
87  virtual int BeginUpdate(const std::string& curVersion, const char* sUpdaterName = NULL) = 0;
88 
90  virtual void ActivateAutoUpdater(const std::string& sMsg) = 0;
91 
93  virtual void OnMessageCallback(NPLInterface::NPLObjectProxy& msg) = 0;
94 
100  virtual AutoUpdaterProgress WaitForCompletion(IAutoUpdaterCallback* pCallback = 0) = 0;
101 
103  virtual bool GetUpdaterMessage(ProgressMessage& msg) = 0;
104 
106  virtual bool PeekUpdaterMessage(ProgressMessage& msg) = 0;
107 
109  virtual void ExitUpdater() = 0;
110 
112  virtual void ApplyPatch() = 0;
113  };
114 
118  {
119  public:
122 
123  public:
127  virtual void SetUpdaterDllPath(const char* sDllPath = NULL);
128 
130  virtual void ActivateAutoUpdater(const std::string& sMsg);
131 
135  virtual int BeginUpdate(const std::string& curVersion, const char* sUpdaterName = NULL);
136 
138  virtual void OnProgress(AutoUpdaterProgress eventType, const char* msg=NULL, int finishcount=0, int allcount=0);
139 
142 
145 
147  virtual bool GetUpdaterMessage(ProgressMessage& msg);
148 
150  virtual bool PeekUpdaterMessage(ProgressMessage& msg);
151 
153  virtual void ExitUpdater();
154 
156  virtual void ApplyPatch();
157  public:
159  virtual const std::string& GetName() const;
160 
164  virtual int activate(const char * sNPLFilename, const char* sCode, int nCodeLength=0, int priority=2, int reliability=4);
165 
174  virtual NPLReturnCode Activate_async(const std::string & filepath, const char * code = NULL,int nLength=0, int priority=0);
175 
177  virtual NPLReturnCode ActivateLocal(const char* filepath, const char * code = NULL,int nLength=0, int priority=0);
178 
185  virtual NPLReturnCode Activate_async(NPLMessage_ptr& msg, int priority=0);
186 
195  virtual NPLReturnCode SendMessage(NPLMessage_ptr& msg, int priority=0);
196 
198  virtual const char* GetCurrentMsg();
199 
201  virtual int GetCurrentMsgLength();
202 
204  virtual INPLRuntime* GetNPLRuntime();
205 
211  virtual void WriteLog(const char* text, int nTextLen=0, int nLogType = 0);
212 
214  //
215  // Timer functions
216  //
218 
230  virtual bool SetTimer(int nIDEvent, float fElapse, const char* sNeuronFile) {return false;};
231 
239  virtual bool KillTimer(int nIDEvent) { return false;};
240 
251  virtual bool ChangeTimer(int nIDEvent, int dueTime, int period) { return false;};
252 
254  virtual void SetUpdateUrl(const std::string& updateurl);
255  virtual void RegisterFile(const char* sFilename, INPLActivationFile* pFileHandler = NULL);
256 
257  virtual void call(const char * sNPLFilename, const char* sCode, int nCodeLength = 0);
258  protected:
260  const char* m_current_msg;
261 
264 
266  std::string m_name;
267 
269  std::string m_updateurl;
270 
273 
274 
275  AutoUpdaterProgress m_progress_status;
276  ParaEngine::Mutex m_mutex;
277  ParaEngine::Semaphore m_semaphore;
278 
280  std::queue<ProgressMessage> m_msgs;
281 
283  std::string m_session_dir;
285  std::string m_sApplyPatchMsg;
288 
289  IAutoUpdaterCallback* m_pUpdaterCallback;
290  };
291 }
NPL object proxy.
Definition: NPLInterface.hpp:1035
static string GetCurrentMsg(System.IntPtr npl_runtime_state)
Get the current incoming message of a npl_runtime_state.
virtual int BeginUpdate(const std::string &curVersion, const char *sUpdaterName=NULL)=0
start updating the client in the current working directory.
define this to enable debugging of NPL code in visual studio
Definition: INPL.h:9
virtual void ActivateAutoUpdater(const std::string &sMsg)=0
call the auto updater.
INPLRuntimeState interface for DLL interface.
Definition: INPLRuntimeState.h:27
std::queue< ProgressMessage > m_msgs
all messages
Definition: AutoUpdaterClient.h:280
virtual void ApplyPatch()=0
apply the recently downloaded patch
virtual bool PeekUpdaterMessage(ProgressMessage &msg)=0
Peek a progress message from the queue.
const char * m_current_msg
pointer to the current message.
Definition: AutoUpdaterClient.h:260
ParaEngine::CPluginLoader m_auto_updater_plugin
the Auto updater plugin
Definition: AutoUpdaterClient.h:272
a DLL/so plug-in loaded explicitly at runtime.
Definition: PluginLoader.hpp:51
virtual bool ChangeTimer(int nIDEvent, int dueTime, int period)
Changes the start time and the interval between method invocations for a timer, using 32-bit signed i...
Definition: AutoUpdaterClient.h:251
virtual AutoUpdaterProgress WaitForCompletion(IAutoUpdaterCallback *pCallback=0)=0
this function returns until auto updater is finished.
progress message
Definition: AutoUpdaterClient.h:50
cross platform condition variable.
Definition: Semaphore.hpp:21
virtual bool GetUpdaterMessage(ProgressMessage &msg)=0
Get a progress message from the queue.
virtual bool SetTimer(int nIDEvent, float fElapse, const char *sNeuronFile)
creates a timer with the specified time-out value [thread safe]
Definition: AutoUpdaterClient.h:230
cross platform mutex
Definition: Mutex.hpp:88
std::string m_session_dir
the directory where the downloaded core update files are cached.
Definition: AutoUpdaterClient.h:283
Definition: inftrees.h:24
virtual void OnMessageCallback(NPLInterface::NPLObjectProxy &msg)=0
this function is called whenever we receive a message from autoupdater.dll
Definition: INPLAcitvationFile.h:18
progress call back.
Definition: AutoUpdaterClient.h:66
std::string m_updateurl
get update url
Definition: AutoUpdaterClient.h:269
virtual void OnProgress(AutoUpdaterProgress eventType, const char *msg=NULL, int finishcount=0, int allcount=0)=0
This function is called for update progress.
static void activate(System.IntPtr npl_runtime_state, string file_name, string msg)
activate a local or remote file
std::string m_updater_plugin_path
autoupdater.dll file path.
Definition: AutoUpdaterClient.h:287
auto updater interface.
Definition: AutoUpdaterClient.h:31
std::string m_name
the name of this runtime state.
Definition: AutoUpdaterClient.h:266
virtual bool KillTimer(int nIDEvent)
Destroys the specified timer [thread safe].
Definition: AutoUpdaterClient.h:239
NPL Runtime Environment interface.
Definition: INPLRuntime.h:30
std::string m_sApplyPatchMsg
apply patch message
Definition: AutoUpdaterClient.h:285
AutoUpdaterProgress
auto update progress
Definition: AutoUpdaterClient.h:35
CAutoUpdaterClietn also implements a dummy INPL Runtime state, so that it can receive call back from ...
Definition: AutoUpdaterClient.h:117
int m_current_msg_length
length of the current message.
Definition: AutoUpdaterClient.h:263
virtual void ExitUpdater()=0
join all threads and unload dll.
virtual void SetUpdaterDllPath(const char *sDllPath=NULL)=0
set the autoupdater.dll file path