static int parse_loader(JSON_Object* loader_json, GATEWAY_MODULE_LOADER_INFO* loader_info) { int result; // get loader name; we assume it is "native" if the JSON doesn't have a name /*Codes_SRS_NATIVEMODULEHOST_17_013: [ NativeModuleHost_Create shall get "name" string from the "outprocess.loader" object. ]*/ const char* loader_name = json_object_get_string(loader_json, LOADER_NAME_KEY); if (loader_name == NULL) { /*Codes_SRS_NATIVEMODULEHOST_17_014: [ If the loader name string is not present, then NativeModuleHost_Create shall assume the loader is the native dynamic library loader name. ]*/ loader_name = DYNAMIC_LOADER_NAME; } // locate the loader /*Codes_SRS_NATIVEMODULEHOST_17_015: [ NativeModuleHost_Create shall find the module loader by name. ]*/ const MODULE_LOADER* loader = ModuleLoader_FindByName(loader_name); if (loader == NULL) { /*Codes_SRS_NATIVEMODULEHOST_17_026: [ If any step above fails, then NativeModuleHost_Create shall free all resources allocated and return NULL. ]*/ LogError("Loader JSON has a non-existent loader 'name' specified - %s.", loader_name); result = __LINE__; } else { loader_info->loader = loader; // get entrypoint /*Codes_SRS_NATIVEMODULEHOST_17_016: [ NativeModuleHost_Create shall get "entrypoint" string from the "outprocess.loader" object. ]*/ JSON_Value* entrypoint_json = json_object_get_value(loader_json, LOADER_ENTRYPOINT_KEY); if (entrypoint_json == NULL) { /*Codes_SRS_NATIVEMODULEHOST_17_026: [ If any step above fails, then NativeModuleHost_Create shall free all resources allocated and return NULL. ]*/ LogError("An error occurred when getting the entrypoint for loader - %s.", loader_name); result = __LINE__; } else { /*Codes_SRS_NATIVEMODULEHOST_17_017: [ NativeModuleHost_Create shall parse the entrypoint string. ]*/ loader_info->entrypoint = loader->api->ParseEntrypointFromJson(loader, entrypoint_json); if (loader_info->entrypoint == NULL) { /*Codes_SRS_NATIVEMODULEHOST_17_026: [ If any step above fails, then NativeModuleHost_Create shall free all resources allocated and return NULL. ]*/ LogError("An error occurred when parsing the entrypoint for loader - %s.", loader_name); result = __LINE__; } else { result = 0; } } } return result; }
MODULE_LOADER* ModuleLoader_GetDefaultLoaderForType(MODULE_LOADER_TYPE type) { MODULE_LOADER* result; switch (type) { case NATIVE: /*Codes_SRS_MODULE_LOADER_13_058: [ ModuleLoader_GetDefaultLoaderForType shall return a non-NULL MODULE_LOADER pointer when the loader type is a recongized type. ]*/ result = ModuleLoader_FindByName(DYNAMIC_LOADER_NAME); break; #ifdef NODE_BINDING_ENABLED case NODEJS: /*Codes_SRS_MODULE_LOADER_13_058: [ ModuleLoader_GetDefaultLoaderForType shall return a non-NULL MODULE_LOADER pointer when the loader type is a recongized type. ]*/ result = ModuleLoader_FindByName(NODE_LOADER_NAME); break; #endif #ifdef JAVA_BINDING_ENABLED case JAVA: /*Codes_SRS_MODULE_LOADER_13_058: [ ModuleLoader_GetDefaultLoaderForType shall return a non-NULL MODULE_LOADER pointer when the loader type is a recongized type. ]*/ result = ModuleLoader_FindByName(JAVA_LOADER_NAME); break; #endif #ifdef DOTNET_BINDING_ENABLED case DOTNET: /*Codes_SRS_MODULE_LOADER_13_058: [ ModuleLoader_GetDefaultLoaderForType shall return a non-NULL MODULE_LOADER pointer when the loader type is a recongized type. ]*/ result = ModuleLoader_FindByName(DOTNET_LOADER_NAME); break; #endif default: /*Codes_SRS_MODULE_LOADER_13_057: [ ModuleLoader_GetDefaultLoaderForType shall return NULL if type is not a recongized loader type. ]*/ result = NULL; break; } return result; }