Hide CPlugin timestamp management details.

This commit is contained in:
David Anderson 2015-09-16 21:32:16 -07:00
parent d5d7e8c9cf
commit 0e1a34a4d7
2 changed files with 28 additions and 33 deletions

View File

@ -64,7 +64,7 @@ CPlugin::CPlugin(const char *file)
m_ident(nullptr),
m_bGotAllLoaded(false),
m_FileVersion(0),
m_LastAccess(0),
m_LastFileModTime(0),
m_handle(BAD_HANDLE)
{
static int MySerial = 0;
@ -150,6 +150,7 @@ CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
fclose(fp);
pPlugin->m_LastFileModTime = pPlugin->GetFileTimeStamp();
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()
{
return m_pPhrases;
@ -898,7 +889,7 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
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)
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)
*aResult = pPlugin;
@ -966,7 +953,7 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
LoadRes res;
*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;
return NULL;
@ -1016,7 +1003,7 @@ void CPluginManager::LoadAutoPlugin(const char *plugin)
LoadRes res;
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);
pl->SetErrorState(
@ -2365,14 +2352,21 @@ void CPluginManager::RefreshAll()
for (auto iter = tmp_list.begin(); iter != tmp_list.end(); iter++)
{
CPlugin *pl = (*iter);
time_t t = pl->GetFileTimeStamp();
if (!t || t > pl->GetTimeStamp()) {
pl->SetTimeStamp(t);
if (pl->HasUpdatedFile())
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)
{
List<IPluginsListener *>::iterator iter;

View File

@ -169,8 +169,8 @@ public:
{
return strcmp(plugin->m_filename, file) == 0;
}
public:
public:
/**
* Sets an error state on the plugin
*/
@ -221,13 +221,8 @@ public:
* Get languages info.
*/
IPhraseCollection *GetPhrases();
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.
bool WasRunning();
@ -250,13 +245,19 @@ public:
void LibraryActions(LibraryAction action);
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:
bool ReadInfo();
void SetTimeStamp(time_t t);
void DependencyDropped(CPlugin *pOwner);
bool TryCompile(char *error, size_t maxlength);
private:
time_t GetFileTimeStamp();
private:
// This information is static for the lifetime of the plugin.
char m_filename[PLATFORM_MAX_PATH];
@ -285,7 +286,7 @@ private:
// Information that survives past eviction.
List<String> m_RequiredLibs;
List<String> m_Libraries;
time_t m_LastAccess;
time_t m_LastFileModTime;
Handle_t m_handle;
char m_DateTime[256];
@ -445,7 +446,7 @@ public:
void ListPluginsToClient(CPlayer *player, const CCommand &args);
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);