Hide CPlugin timestamp management details.
This commit is contained in:
parent
d5d7e8c9cf
commit
0e1a34a4d7
@ -64,7 +64,7 @@ CPlugin::CPlugin(const char *file)
|
|||||||
m_ident(nullptr),
|
m_ident(nullptr),
|
||||||
m_bGotAllLoaded(false),
|
m_bGotAllLoaded(false),
|
||||||
m_FileVersion(0),
|
m_FileVersion(0),
|
||||||
m_LastAccess(0),
|
m_LastFileModTime(0),
|
||||||
m_handle(BAD_HANDLE)
|
m_handle(BAD_HANDLE)
|
||||||
{
|
{
|
||||||
static int MySerial = 0;
|
static int MySerial = 0;
|
||||||
@ -150,6 +150,7 @@ CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
pPlugin->m_LastFileModTime = pPlugin->GetFileTimeStamp();
|
||||||
return pPlugin;
|
return pPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,16 +615,6 @@ time_t CPlugin::GetFileTimeStamp()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t CPlugin::GetTimeStamp()
|
|
||||||
{
|
|
||||||
return m_LastAccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPlugin::SetTimeStamp(time_t t)
|
|
||||||
{
|
|
||||||
m_LastAccess = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPhraseCollection *CPlugin::GetPhrases()
|
IPhraseCollection *CPlugin::GetPhrases()
|
||||||
{
|
{
|
||||||
return m_pPhrases;
|
return m_pPhrases;
|
||||||
@ -898,7 +889,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
|
|||||||
libsys->CloseDirectory(dir);
|
libsys->CloseDirectory(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool debug, PluginType type, char error[], size_t maxlength)
|
LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool debug, PluginType type, char error[], size_t maxlength)
|
||||||
{
|
{
|
||||||
if (m_LoadingLocked)
|
if (m_LoadingLocked)
|
||||||
return LoadRes_NeverLoad;
|
return LoadRes_NeverLoad;
|
||||||
@ -950,10 +941,6 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the time stamp */
|
|
||||||
time_t t = pPlugin->GetFileTimeStamp();
|
|
||||||
pPlugin->SetTimeStamp(t);
|
|
||||||
|
|
||||||
if (aResult)
|
if (aResult)
|
||||||
*aResult = pPlugin;
|
*aResult = pPlugin;
|
||||||
|
|
||||||
@ -966,7 +953,7 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
|
|||||||
LoadRes res;
|
LoadRes res;
|
||||||
|
|
||||||
*wasloaded = false;
|
*wasloaded = false;
|
||||||
if ((res=_LoadPlugin(&pl, path, true, PluginType_MapUpdated, error, maxlength)) == LoadRes_Failure)
|
if ((res=LoadPlugin(&pl, path, true, PluginType_MapUpdated, error, maxlength)) == LoadRes_Failure)
|
||||||
{
|
{
|
||||||
delete pl;
|
delete pl;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1016,7 +1003,7 @@ void CPluginManager::LoadAutoPlugin(const char *plugin)
|
|||||||
LoadRes res;
|
LoadRes res;
|
||||||
char error[255] = "Unknown error";
|
char error[255] = "Unknown error";
|
||||||
|
|
||||||
if ((res=_LoadPlugin(&pl, plugin, false, PluginType_MapUpdated, error, sizeof(error))) == LoadRes_Failure)
|
if ((res=LoadPlugin(&pl, plugin, false, PluginType_MapUpdated, error, sizeof(error))) == LoadRes_Failure)
|
||||||
{
|
{
|
||||||
g_Logger.LogError("[SM] Failed to load plugin \"%s\": %s.", plugin, error);
|
g_Logger.LogError("[SM] Failed to load plugin \"%s\": %s.", plugin, error);
|
||||||
pl->SetErrorState(
|
pl->SetErrorState(
|
||||||
@ -2365,14 +2352,21 @@ void CPluginManager::RefreshAll()
|
|||||||
for (auto iter = tmp_list.begin(); iter != tmp_list.end(); iter++)
|
for (auto iter = tmp_list.begin(); iter != tmp_list.end(); iter++)
|
||||||
{
|
{
|
||||||
CPlugin *pl = (*iter);
|
CPlugin *pl = (*iter);
|
||||||
time_t t = pl->GetFileTimeStamp();
|
if (pl->HasUpdatedFile())
|
||||||
if (!t || t > pl->GetTimeStamp()) {
|
|
||||||
pl->SetTimeStamp(t);
|
|
||||||
UnloadPlugin(pl);
|
UnloadPlugin(pl);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CPlugin::HasUpdatedFile()
|
||||||
|
{
|
||||||
|
time_t t = GetFileTimeStamp();
|
||||||
|
if (!t || t > m_LastFileModTime) {
|
||||||
|
m_LastFileModTime = t;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void CPluginManager::_SetPauseState(CPlugin *pl, bool paused)
|
void CPluginManager::_SetPauseState(CPlugin *pl, bool paused)
|
||||||
{
|
{
|
||||||
List<IPluginsListener *>::iterator iter;
|
List<IPluginsListener *>::iterator iter;
|
||||||
|
@ -169,8 +169,8 @@ public:
|
|||||||
{
|
{
|
||||||
return strcmp(plugin->m_filename, file) == 0;
|
return strcmp(plugin->m_filename, file) == 0;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* Sets an error state on the plugin
|
* Sets an error state on the plugin
|
||||||
*/
|
*/
|
||||||
@ -221,13 +221,8 @@ public:
|
|||||||
* Get languages info.
|
* Get languages info.
|
||||||
*/
|
*/
|
||||||
IPhraseCollection *GetPhrases();
|
IPhraseCollection *GetPhrases();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Returns the modification time during last plugin load.
|
|
||||||
time_t GetTimeStamp();
|
|
||||||
|
|
||||||
// Returns the current modification time of the plugin file.
|
|
||||||
time_t GetFileTimeStamp();
|
|
||||||
|
|
||||||
// Returns true if the plugin was running, but is now invalid.
|
// Returns true if the plugin was running, but is now invalid.
|
||||||
bool WasRunning();
|
bool WasRunning();
|
||||||
|
|
||||||
@ -250,13 +245,19 @@ public:
|
|||||||
void LibraryActions(LibraryAction action);
|
void LibraryActions(LibraryAction action);
|
||||||
void SyncMaxClients(int max_clients);
|
void SyncMaxClients(int max_clients);
|
||||||
|
|
||||||
|
// Returns true if the plugin's underlying file structure has a newer
|
||||||
|
// modification time than either when it was first instantiated or
|
||||||
|
// since the last call to HasUpdatedFile().
|
||||||
|
bool HasUpdatedFile();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool ReadInfo();
|
bool ReadInfo();
|
||||||
void SetTimeStamp(time_t t);
|
|
||||||
void DependencyDropped(CPlugin *pOwner);
|
void DependencyDropped(CPlugin *pOwner);
|
||||||
|
|
||||||
bool TryCompile(char *error, size_t maxlength);
|
bool TryCompile(char *error, size_t maxlength);
|
||||||
|
|
||||||
|
private:
|
||||||
|
time_t GetFileTimeStamp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This information is static for the lifetime of the plugin.
|
// This information is static for the lifetime of the plugin.
|
||||||
char m_filename[PLATFORM_MAX_PATH];
|
char m_filename[PLATFORM_MAX_PATH];
|
||||||
@ -285,7 +286,7 @@ private:
|
|||||||
// Information that survives past eviction.
|
// Information that survives past eviction.
|
||||||
List<String> m_RequiredLibs;
|
List<String> m_RequiredLibs;
|
||||||
List<String> m_Libraries;
|
List<String> m_Libraries;
|
||||||
time_t m_LastAccess;
|
time_t m_LastFileModTime;
|
||||||
Handle_t m_handle;
|
Handle_t m_handle;
|
||||||
char m_DateTime[256];
|
char m_DateTime[256];
|
||||||
|
|
||||||
@ -445,7 +446,7 @@ public:
|
|||||||
|
|
||||||
void ListPluginsToClient(CPlayer *player, const CCommand &args);
|
void ListPluginsToClient(CPlayer *player, const CCommand &args);
|
||||||
private:
|
private:
|
||||||
LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
|
LoadRes LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
|
||||||
|
|
||||||
void LoadAutoPlugin(const char *plugin);
|
void LoadAutoPlugin(const char *plugin);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user