Example #1
0
bool NeuronFactory::loadModel(std::string model_type) {

    std::string library_name = getLibraryName(model_type);

    void* handle = dlopen(library_name.c_str(), RTLD_LAZY);
    if (!handle) {
        std::cerr << "Cannot load " << library_name << ": " << dlerror() << std::endl;
        return false;
    }
    _model_types.push_back(model_type);
    handles[library_name] = handle;

}
Example #2
0
bool NeuronFactory::create(std::string model_type, NeuronParams* np, Neuron* &n) {
    std::string library_name = getLibraryName(model_type);
	
    void* handle;

    if (handles.find(library_name) != handles.end()) {
        handle = handles.find(library_name)->second;
    } else {
        std::cerr << "Unknown Model Type: \"" << model_type << "\"" << std::endl;
        return false;
    }

    // reset errors
    dlerror();

    // load the symbols
    create_t* create_model = (create_t*) dlsym(handle, "create");
    const char* dlsym_error = dlerror();
    if (dlsym_error) {
        std::cerr << "Cannot load symbol create: " << dlsym_error << std::endl;
        std::cerr << "This does not appear to be a valid dtnet neuron model library." << std::endl;
        return false;
    }

    // create an instance of the class
    n = create_model();

    // copy in the parameters pass in if they are not null.
    if (np != NULL) n->params = *np;
    n->model = model_type;

    this->models[n] = library_name;


    return true;
}
Example #3
0
void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize)
{
    // Before we can load a library, we need to find out its location. As
    // we're powerless here in C/C++, we need the JNI interface to communicate
    // with the attached Java virtual machine and perform some Java calls in
    // order to retrieve the absolute path of our libraries.
    //
    // Here's the snippet of Java code it performs:
    // --------------------------------------------
    // ai = getPackageManager().getActivityInfo(getIntent().getComponent(), PackageManager.GET_META_DATA);
    // File libraryFile = new File(ai.applicationInfo.nativeLibraryDir, System.mapLibraryName(libname));
    // String path = libraryFile.getPath();
    //
    // With libname being the library name such as "jpeg".

    // Retrieve JNI environment and JVM instance
    JavaVM* lJavaVM = activity->vm;
    JNIEnv* lJNIEnv = activity->env;

    // Retrieve the NativeActivity
    jobject ObjectNativeActivity = activity->clazz;
    jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity);

    // Retrieve the ActivityInfo
    jmethodID MethodGetPackageManager = lJNIEnv->GetMethodID(ClassNativeActivity, "getPackageManager", "()Landroid/content/pm/PackageManager;");
    jobject ObjectPackageManager = lJNIEnv->CallObjectMethod(ObjectNativeActivity, MethodGetPackageManager);

    jmethodID MethodGetIndent = lJNIEnv->GetMethodID(ClassNativeActivity, "getIntent", "()Landroid/content/Intent;");
    jobject ObjectIntent = lJNIEnv->CallObjectMethod(ObjectNativeActivity, MethodGetIndent);

    jclass ClassIntent = lJNIEnv->FindClass("android/content/Intent");
    jmethodID MethodGetComponent = lJNIEnv->GetMethodID(ClassIntent, "getComponent", "()Landroid/content/ComponentName;");

    jobject ObjectComponentName = lJNIEnv->CallObjectMethod(ObjectIntent, MethodGetComponent);

    jclass ClassPackageManager = lJNIEnv->FindClass("android/content/pm/PackageManager");

    jfieldID FieldGET_META_DATA = lJNIEnv->GetStaticFieldID(ClassPackageManager, "GET_META_DATA", "I");
    jint GET_META_DATA = lJNIEnv->GetStaticIntField(ClassPackageManager, FieldGET_META_DATA);

    jmethodID MethodGetActivityInfo = lJNIEnv->GetMethodID(ClassPackageManager, "getActivityInfo", "(Landroid/content/ComponentName;I)Landroid/content/pm/ActivityInfo;");
    jobject ObjectActivityInfo = lJNIEnv->CallObjectMethod(ObjectPackageManager, MethodGetActivityInfo, ObjectComponentName, GET_META_DATA);

    // Load our libraries in reverse order
#if defined(STL_LIBRARY)
#define _SFML_QS(s) _SFML_S(s)
#define _SFML_S(s) #s
    loadLibrary(_SFML_QS(STL_LIBRARY), lJNIEnv, ObjectActivityInfo);
#undef _SFML_S
#undef _SFML_QS
#endif
    loadLibrary("openal", lJNIEnv, ObjectActivityInfo);

#if !defined(SFML_DEBUG)
    loadLibrary("sfml-system", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-window", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-graphics", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-audio", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-network", lJNIEnv, ObjectActivityInfo);
#else
    loadLibrary("sfml-system-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-window-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-graphics-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-audio-d", lJNIEnv, ObjectActivityInfo);
    loadLibrary("sfml-network-d", lJNIEnv, ObjectActivityInfo);
#endif

    void* handle = loadLibrary(getLibraryName(lJNIEnv, ObjectActivityInfo), lJNIEnv, ObjectActivityInfo);

    // Call the original ANativeActivity_onCreate function
    activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");

    if (!ANativeActivity_onCreate)
    {
        LOGE("sfml-activity: Undefined symbol ANativeActivity_onCreate");
        exit(1);
    }

    ANativeActivity_onCreate(activity, savedState, savedStateSize);
}
const NAString
StmtDDLDropLibrary::displayLabel1() const
{
  return NAString("Library name: ") + getLibraryName();
}
Example #5
0
void APILoader::loadLibrary(ApiLibrary apiLibrary, LoadMode mode) {

    if (apiLibrary == LIBRARY_NONE) {
        return;
    }

    std::string libraryName = getLibraryName(apiLibrary);

    if (m_LoadedLibraries.find(libraryName) == m_LoadedLibraries.end()) {

#ifdef _WIN32
        if (mode == LoadMode::LAZY && !GetModuleHandle(libraryName.c_str())) {
            //Will load this later. This is used to avoid calling LoadLibrary() too early in Win.
            return;
        }
#else
        DGL_UNUSED(mode);
#endif

        std::vector<std::string> libSearchPath;


        libSearchPath.push_back("");
#ifdef _WIN32
        char buffer[1000];
#ifndef _WIN64
        if (GetSystemWow64Directory(buffer, sizeof(buffer)) > 0) {
            // we are running 32bit app on 64 bit windows
            libSearchPath.push_back(buffer + std::string("\\"));
        }
#endif
        if (GetSystemDirectory(buffer, sizeof(buffer)) > 0) {
            // we are running on native system (32 on 32 or 64 on 64)
            libSearchPath.push_back(buffer + std::string("\\"));
        }

#ifndef _WIN64
        libSearchPath.push_back("C:\\Windows\\SysWOW64\\");
#endif
        libSearchPath.push_back("C:\\Windows\\System32\\");
        libSearchPath.push_back(".");
#endif

        std::shared_ptr<DynamicLibrary> openGLLibraryHandle = nullptr;

        for (size_t i = 0; i < libSearchPath.size() && !openGLLibraryHandle;
             i++) {
            openGLLibraryHandle = EarlyGlobalState::getDynLoader().getLibrary(
                    (libSearchPath[i] + libraryName).c_str());
        }

#if DGL_HAVE_WA(ANDROID_MISSING_LIBGL)
        if (!openGLLibraryHandle && apiLibrary == LIBRARY_GL) {
            //Some Android devices support 'big' OpenGL, but libGL.so is not provided.
            //Instead fake the load process with *eglGetProcAddress

            openGLLibraryHandle = std::make_shared<FakeDynamicLibrary>(this);
        }
#endif

        if (!openGLLibraryHandle) {
            std::string msg = std::string("Cannot load ") + libraryName +
                              "  system library";
            Os::fatal(msg.c_str());
        } else {
            m_LoadedLibraries[libraryName] = openGLLibraryHandle;
        }
    }

    DynamicLibrary* library = m_LoadedLibraries[libraryName].get();

#ifdef _WIN32
    HookSession hookSession;
#endif

    // g_DirectPointers is now filled with opengl32.dll pointers
    // we will now detour (hook) them all, so g_DirectPointers will still lead
    // to original opengl32.dll, but
    // application will always call us.
    for (int i = 0; i < Entrypoints_NUM; i++) {
        if (!(g_DirectPointers[i].libraryMask & apiLibrary)) {
            // Do not load - entrypoint does not belong to currently loaded API
            continue;
        }

        if (m_LoadedApiLibraries & g_DirectPointers[i].libraryMask) {
            // Do not load - entrypoint belongs to already loaded API
            continue;
        }

        // this sets g_DirectPointers[i].ptr
        setPointer(i, getGLPointer(*library, i));

        if (g_DirectPointers[i].ptr) {
// this entrypoint was loaded from OpenGL32.dll, detour it!
#ifdef _WIN32
            dgl_func_ptr hookPtr = getWrapperPointer(i);
            if (!hookSession.hook(&g_DirectPointers[i].ptr, hookPtr)) {
                Os::fatal("Cannot hook %s() function.", GetEntryPointName(i));
            }
#endif
        }
    }
    if (apiLibrary == LIBRARY_EGL || apiLibrary == LIBRARY_WGL ||
        apiLibrary == LIBRARY_GLX)
        m_GlueLibrary = apiLibrary;

    m_LoadedApiLibraries |= apiLibrary;
}
Example #6
0
void NeuronFactory::registerModel(std::string model_type, Neuron* n) {    
    std::string library_name = getLibraryName(model_type);
    this->models[n] = library_name;
}
Example #7
0
Common::Error BuriedEngine::run() {
	_console = new BuriedConsole(this);

#ifndef USE_ICONV
	// The Japanese version needs iconv support
	if (getLanguage() == Common::JA_JPN)
		return Common::Error(Common::kUnknownError, "No iconv support available");
#endif

	if (isTrueColor()) {
		initGraphics(640, 480, true, 0);

		if (_system->getScreenFormat().bytesPerPixel == 1)
			return Common::kUnsupportedColorMode;
	} else {
		initGraphics(640, 480, true);
	}

	if (isWin95()) {
		_mainEXE = new DatabasePE();
		_library = new DatabasePE();
	} else if (isCompressed()) {
		_mainEXE = new DatabaseNECompressed();
		_library = new DatabaseNECompressed();
	} else {
		_mainEXE = new DatabaseNE();

		// Demo only uses the main EXE
		if (!isDemo())
			_library = new DatabaseNE();
	}

	if (!_mainEXE->load(getEXEName()))
		error("Failed to load main EXE '%s'", getEXEName().c_str());

	if (_library && !_library->load(getLibraryName()))
		error("Failed to load library DLL '%s'", getLibraryName().c_str());

	syncSoundSettings();

	_gfx = new GraphicsManager(this);
	_sound = new SoundManager(this);
	_mainWindow = new FrameWindow(this);
	_mainWindow->showWindow(Window::kWindowShow);

	if (isDemo()) {
		((FrameWindow *)_mainWindow)->showTitleSequence();
		((FrameWindow *)_mainWindow)->showMainMenu();
	} else {
		bool doIntro = true;

		if (ConfMan.hasKey("save_slot")) {
			uint32 gameToLoad = ConfMan.getInt("save_slot");
			doIntro = (loadGameState(gameToLoad).getCode() != Common::kNoError);

			// If the trial version tries to load a game without a time
			// zone that's part of the trial version, force the intro.
			if (isTrial() && !((FrameWindow *)_mainWindow)->getMainChildWindow())
				doIntro = true;
		}

		// Play the intro only if we're starting from scratch
		if (doIntro)
			((FrameWindow *)_mainWindow)->showClosingScreen();
	}

	while (!shouldQuit()) {
		updateVideos();

		pollForEvents();

		sendAllMessages();

		_gfx->updateScreen();
		_system->delayMillis(10);
	}

	return Common::kNoError;
}
Example #8
0
void guiGate::saveGate(XMLParser* xparse) {
	float x, y;
	this->getGLcoords(x, y);

	xparse->openTag("gate");
	xparse->openTag("ID");
	ostringstream oss;
	oss << gateID;
	xparse->writeTag("ID", oss.str());
	xparse->closeTag("ID");
	xparse->openTag("type");
	xparse->writeTag("type", libGateName);
	xparse->closeTag("type");
	oss.str("");
	xparse->openTag("position");
	oss << x << "," << y;
	xparse->writeTag("position", oss.str());
	xparse->closeTag("position");
	map< string, guiWire* >::iterator pC = connections.begin();
	while(pC != connections.end()) {
		xparse->openTag((isInput[pC->first] ? "input" : "output"));
		xparse->openTag("ID");
		xparse->writeTag("ID", pC->first);
		xparse->closeTag("ID");
		oss.str("");
		oss <<(pC->second)->getID() << " ";
		xparse->writeTag((isInput[pC->first] ? "input" : "output"), oss.str());
		xparse->closeTag((isInput[pC->first] ? "input" : "output"));
		pC++;
	}
	map< string, string >::iterator pParams = gparams.begin();
	while(pParams != gparams.end()) {
		xparse->openTag("gparam");
		oss.str("");
		oss << pParams->first << " " << pParams->second;
		xparse->writeTag("gparam", oss.str());
		xparse->closeTag("gparam");
		pParams++;
	}
	pParams = lparams.begin();
	LibraryGate lg = wxGetApp().libraries[getLibraryName()][getLibraryGateName()];
	while(pParams != lparams.end()) {
		bool found = false;
		for(unsigned int i = 0; i < lg.dlgParams.size() && !found; i++) {
			if(lg.dlgParams[i].isGui) continue;
			if((lg.dlgParams[i].type == "FILE_IN" || lg.dlgParams[i].type == "FILE_OUT") &&
				lg.dlgParams[i].name == pParams->first) found = true;
		}
		if(found) { pParams++; continue; }
		xparse->openTag("lparam");
		oss.str("");
		oss << pParams->first << " " << pParams->second;
		xparse->writeTag("lparam", oss.str());
		xparse->closeTag("lparam");
		pParams++;
	}
	
	//*********************************
	//Edit by Joshua Lansford 6/06/2007
	//I want the ram files to save their contents to file
	//with the circuit.  However, I don't want to send
	//an entire page of data up to the gui each time
	//an entry changes.
	//This way the ram gate can intelegently save what
	//it wants to into the file.
	//Also any other gate that wishes too, can also
	//save specific stuff.
	this->saveGateTypeSpecifics(xparse);
	//End of edit***********************
	
	xparse->closeTag("gate");	
}