Exemplo n.º 1
0
void DServer::class_factory()
{
#ifdef _TG_WINDOWS_
	Tango::Util *tg = Tango::Util::instance();
	string exe_name = tg->get_ds_exec_name();
	exe_name = exe_name + ".exe";
	HMODULE mod;
	FARPROC proc;
	convertor conv;
	PTR tmp;

	if (tg->is_py_ds() == false)
	{
		if ((mod = GetModuleHandle(exe_name.c_str())) == NULL)
		{
			cerr << "Oups, no class defined in this server. Exiting ..." << endl;
			exit(-1);
		}
	}
	else
	{
		if ((mod = GetModuleHandle(TANGO_PY_MOD_NAME)) == NULL)
		{
			cerr << "Oups, no class defined in this server. Exiting ..." << endl;
			exit(-1);
		}
	}

//
// Use the mangled name to find the user DServer::class_factory method
//
// Due to the fact that on Windows 64 bits we have both _WIN32 and _WIN64
// defined, start by testing _WIN64 (See tango_config.h)
//

#ifdef _WIN64
	if ((proc = GetProcAddress(mod,"?class_factory@DServer@Tango@@AEAAXXZ")) == NULL)
#elif _WIN32 /* WIN32 */
	if ((proc = GetProcAddress(mod,"?class_factory@DServer@Tango@@AAEXXZ")) == NULL)
#endif
	{
		cerr << "Oups, no class defined in this server. Exiting ..." << endl;
		exit(-1);
	}
	else
	{
		conv.d = &DServer::stop_polling;
		conv.s = proc;

		tmp = conv.d;
		(this->*tmp)();
	}

#elif __darwin__
	Tango::Util *tg = Tango::Util::instance();
	string exe_name = tg->get_ds_exec_name();
	exe_name = exe_name;

	void *mod;
	void *proc;
	convertor conv;
	PTR tmp;

	if (tg->is_py_ds() == false)
	{
		if ((mod = dlopen (exe_name.c_str(), RTLD_LAZY )) == NULL)
		{
			cerr << "Oups, no class defined in this server. Exiting ..." << endl;
			exit(-1);
		}
	}
	else
	{
		/*
		if ((mod = GetModuleHandle(TANGO_PY_MOD_NAME)) == NULL)
		{
			cerr << "Oups, no class defined in this server. Exiting ..." << endl;
			exit(-1);
		}
		*/
	}

//
// Use the mangled name to find the user DServer::class_factory method
//
// Due to the fact that on Windows 64 bits we have both WIN32 and WIN64
// defined, start by testing WIN64 (See tango_config.h)
//

	if ((proc = dlsym (mod,"_ZN5Tango7DServer13class_factoryEv")) == NULL)
	{
		cerr << "error : " << dlerror() << endl;
		cerr << "Oups, no class defined in this server. Exiting ..." << endl;
		exit(-1);
	}
	else
	{
		conv.d = &DServer::stop_polling;
		conv.s = proc;

		tmp = conv.d;
		(this->*tmp)();
	}
#else
		cerr << "Oups, no class defined in this server. Exiting ..." << endl;
		exit(-1);
#endif

}