summaryrefslogtreecommitdiff
path: root/core/main.cpp
blob: 29d2bd134dbc19195209eed0912cd8ba7923b210 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright 2010 sss
 * This file is part of evil_core.
 * 
 * evil_core is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * evil_core is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with evil_core.  If not, see <http://www.gnu.org/licenses/>.*/


#include "commonheaders.h"

std::list<plugin*> plugins;
boost::mutex plugin_list_mutex;
std::list<service*> services;
boost::mutex service_list_mutex;
std::list<evt_handler*> event_handlers;
boost::mutex event_handlers_mutex;
ACE_Log_Msg logger;
int current_plugin_id = 13;
bool halt_requested = false;


PLUGINLINK pluglink = {&CreateServiceFunction, &CallService, &ServiceExists, &RegisterEventHandler, &RegisterEventType, &ExecuteEvent};

int on_exit()
{
	plugin_list_mutex.lock();
	service_list_mutex.lock();
	if(!services.empty())
	{
		std::list<service*>::iterator end = services.end();
		for(std::list<service*>::iterator i = services.begin(); i != end; ++i)
			delete *i;
		services.clear();
	}
	if(!plugins.empty())
	{
		std::list<plugin*>::iterator end = plugins.end();
		for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i)
			delete *i;
		plugins.clear();
	}
	plugin_list_mutex.unlock();
	service_list_mutex.unlock();
	return 0;
}

#ifdef _WIN32
HINSTANCE hInst;
int __stdcall WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
#else
int ACE_MAIN(int argc, char *argv[])
#endif
{
#ifdef _WIN32
	hInst = hInstance;
#endif
	void load_modules();
	void run_plugins();
	void register_core_services();
	register_core_services();
	logger.log(LM_DEBUG, "Loading plugins...\n");
	load_modules();
	logger.log(LM_DEBUG, "Running plugins...\n");
	run_plugins();
	while(true)
	{
		logger.log(LM_DEBUG, "Main threas sleeping...\n");
		boost::this_thread::sleep(boost::posix_time::seconds(5));
		if(halt_requested)
			break;
	}
	return 0;
}

void terminate()
{
	if(on_exit())
		logger.log(LM_DEBUG, "Something bad happened on exit");
}