changed: the way how plugins work

all your plugin functions can have signature either:
void my_function(PluginInfo & info); or
void my_function();
only the main Init should have:
extern "C" void Init(PluginFunction & info);

added: directory 'plugins' for plugins
added: 'stats' plugin
		  


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@624 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-07-27 20:41:56 +00:00
parent e4683b9a05
commit 031ace3fe5
33 changed files with 1268 additions and 399 deletions

120
plugins/stats/stats.cpp Executable file
View File

@@ -0,0 +1,120 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "stats.h"
#include <fstream>
#include "data.h"
#include "core/log.h"
namespace Stats
{
std::string stats_file;
void ReadStats(std::ifstream & file)
{
file >> stats_start;
file >> stat_global.all;
file >> stat_global.unique;
file >> stat_global.google;
file >> stat_global.yahoo;
size_t len;
file >> len;
Stats s;
long item_id;
for(size_t i = 0 ; i<len && !file.eof() ; ++i)
{
file >> item_id;
file >> s.all;
file >> s.google;
file >> s.yahoo;
stats_tab.insert( std::make_pair(item_id, s) );
}
}
void ReadStats()
{
if( stats_file.empty() )
return;
std::ifstream file(stats_file.c_str());
if( !file )
{
log << log1 << "Stats: I cannot open the stats file: " << stats_file << logend;
return;
}
ReadStats(file);
file.close();
log << log3 << "Stats: statistics loaded from: " << stats_file
<< " (" << stats_tab.size() << " items)" << logend;
}
void SaveStats(std::ofstream & file)
{
file << stats_start << std::endl;
file << stat_global.all << ' ';
file << stat_global.unique << ' ';
file << stat_global.google << ' ';
file << stat_global.yahoo << ' ';
file << std::endl;
file << stats_tab.size() << std::endl;
std::map<long, Stats>::iterator i = stats_tab.begin();
for( ; i != stats_tab.end() ; ++i)
{
file << i->first << ' ';
file << i->second.all << ' ';
file << i->second.google << ' ';
file << i->second.yahoo << ' ';
file << std::endl;
}
}
void SaveStats()
{
if( stats_file.empty() )
return;
std::ofstream file(stats_file.c_str());
if( !file )
{
log << log1 << "Stats: I cannot open the stats file: " << stats_file << logend;
return;
}
SaveStats(file);
file.close();
log << log3 << "Stats: statistics saved to: " << stats_file << logend;
}
} // namespace