mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-04 12:21:54 +00:00
indent
This commit is contained in:
parent
988147a70b
commit
e4450044d7
@ -53,25 +53,29 @@ static void launch_java(switch_core_session_t *session, const char *data, JNIEnv
|
|||||||
jstring args = NULL;
|
jstring args = NULL;
|
||||||
|
|
||||||
Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
|
Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
|
||||||
if (Launcher == NULL) {
|
if (Launcher == NULL)
|
||||||
|
{
|
||||||
(*env)->ExceptionDescribe(env);
|
(*env)->ExceptionDescribe(env);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
|
launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||||
if (launch == NULL) {
|
if (launch == NULL)
|
||||||
|
{
|
||||||
(*env)->ExceptionDescribe(env);
|
(*env)->ExceptionDescribe(env);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid = (*env)->NewStringUTF(env, switch_core_session_get_uuid(session));
|
uuid = (*env)->NewStringUTF(env, switch_core_session_get_uuid(session));
|
||||||
if (uuid == NULL) {
|
if (uuid == NULL)
|
||||||
|
{
|
||||||
(*env)->ExceptionDescribe(env);
|
(*env)->ExceptionDescribe(env);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
args = (*env)->NewStringUTF(env, data);
|
args = (*env)->NewStringUTF(env, data);
|
||||||
if (args == NULL) {
|
if (args == NULL)
|
||||||
|
{
|
||||||
(*env)->ExceptionDescribe(env);
|
(*env)->ExceptionDescribe(env);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -98,10 +102,12 @@ SWITCH_STANDARD_APP(java_function)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
res = (*javaVM)->AttachCurrentThread(javaVM, (void*) &env, NULL);
|
res = (*javaVM)->AttachCurrentThread(javaVM, (void*) &env, NULL);
|
||||||
if (res == JNI_OK) {
|
if (res == JNI_OK)
|
||||||
|
{
|
||||||
launch_java(session, data, env);
|
launch_java(session, data, env);
|
||||||
(*javaVM)->DetachCurrentThread(javaVM);
|
(*javaVM)->DetachCurrentThread(javaVM);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error attaching thread to Java VM!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error attaching thread to Java VM!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,50 +117,62 @@ static switch_status_t load_config(JavaVMOption ** javaOptions, int *optionCount
|
|||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
|
|
||||||
xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
|
xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
|
||||||
if (xml) {
|
if (xml)
|
||||||
|
{
|
||||||
switch_xml_t javavm;
|
switch_xml_t javavm;
|
||||||
switch_xml_t options;
|
switch_xml_t options;
|
||||||
|
|
||||||
javavm = switch_xml_child(cfg, "javavm");
|
javavm = switch_xml_child(cfg, "javavm");
|
||||||
if (javavm != NULL) {
|
if (javavm != NULL)
|
||||||
|
{
|
||||||
const char *path = switch_xml_attr_soft(javavm, "path");
|
const char *path = switch_xml_attr_soft(javavm, "path");
|
||||||
if (path != NULL) {
|
if (path != NULL)
|
||||||
|
{
|
||||||
status = switch_dso_load(&javaVMHandle, path, memoryPool);
|
status = switch_dso_load(&javaVMHandle, path, memoryPool);
|
||||||
if (status != SWITCH_STATUS_SUCCESS)
|
if (status != SWITCH_STATUS_SUCCESS)
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
options = switch_xml_child(cfg, "options");
|
options = switch_xml_child(cfg, "options");
|
||||||
if (options != NULL) {
|
if (options != NULL)
|
||||||
|
{
|
||||||
switch_xml_t option;
|
switch_xml_t option;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
*optionCount = 0;
|
*optionCount = 0;
|
||||||
for (option = switch_xml_child(options, "option"); option; option = option->next) {
|
for (option = switch_xml_child(options, "option"); option; option = option->next)
|
||||||
|
{
|
||||||
const char *value = switch_xml_attr_soft(option, "value");
|
const char *value = switch_xml_attr_soft(option, "value");
|
||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
++*optionCount;
|
++*optionCount;
|
||||||
}
|
}
|
||||||
*optionCount += 1;
|
*optionCount += 1;
|
||||||
*javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
|
*javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
|
||||||
if (*javaOptions == NULL) {
|
if (*javaOptions == NULL)
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
for (option = switch_xml_child(options, "option"); option; option = option->next) {
|
for (option = switch_xml_child(options, "option"); option; option = option->next)
|
||||||
|
{
|
||||||
const char *value = switch_xml_attr_soft(option, "value");
|
const char *value = switch_xml_attr_soft(option, "value");
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
continue;
|
continue;
|
||||||
(*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
|
(*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
|
||||||
if ((*javaOptions)[i].optionString == NULL) {
|
if ((*javaOptions)[i].optionString == NULL)
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
goto close;
|
goto close;
|
||||||
@ -166,7 +184,9 @@ static switch_status_t load_config(JavaVMOption ** javaOptions, int *optionCount
|
|||||||
|
|
||||||
close:
|
close:
|
||||||
switch_xml_free(xml);
|
switch_xml_free(xml);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
@ -179,7 +199,8 @@ static switch_status_t create_java_vm(JavaVMOption * options, int optionCount)
|
|||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
|
|
||||||
status = switch_dso_sym((void*) &pJNI_CreateJavaVM, javaVMHandle, "JNI_CreateJavaVM");
|
status = switch_dso_sym((void*) &pJNI_CreateJavaVM, javaVMHandle, "JNI_CreateJavaVM");
|
||||||
if (status == SWITCH_STATUS_SUCCESS) {
|
if (status == SWITCH_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
JavaVMInitArgs initArgs;
|
JavaVMInitArgs initArgs;
|
||||||
jint res;
|
jint res;
|
||||||
@ -191,14 +212,19 @@ static switch_status_t create_java_vm(JavaVMOption * options, int optionCount)
|
|||||||
initArgs.ignoreUnrecognized = JNI_TRUE;
|
initArgs.ignoreUnrecognized = JNI_TRUE;
|
||||||
|
|
||||||
res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs);
|
res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs);
|
||||||
if (res == JNI_OK) {
|
if (res == JNI_OK)
|
||||||
|
{
|
||||||
(*javaVM)->DetachCurrentThread(javaVM);
|
(*javaVM)->DetachCurrentThread(javaVM);
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
@ -221,16 +247,19 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_java_load)
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
status = switch_core_new_memory_pool(&memoryPool);
|
status = switch_core_new_memory_pool(&memoryPool);
|
||||||
if (status == SWITCH_STATUS_SUCCESS) {
|
if (status == SWITCH_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
status = load_config(&options, &optionCount);
|
status = load_config(&options, &optionCount);
|
||||||
if (status == SWITCH_STATUS_SUCCESS) {
|
if (status == SWITCH_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
status = create_java_vm(options, optionCount);
|
status = create_java_vm(options, optionCount);
|
||||||
if (status == SWITCH_STATUS_SUCCESS)
|
if (status == SWITCH_STATUS_SUCCESS)
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
switch_dso_unload(javaVMHandle);
|
switch_dso_unload(javaVMHandle);
|
||||||
}
|
}
|
||||||
switch_core_destroy_memory_pool(&memoryPool);
|
switch_core_destroy_memory_pool(&memoryPool);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating memory pool\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating memory pool\n");
|
||||||
|
|
||||||
return status == SWITCH_STATUS_SUCCESS ? SWITCH_STATUS_NOUNLOAD : status;
|
return status == SWITCH_STATUS_SUCCESS ? SWITCH_STATUS_NOUNLOAD : status;
|
||||||
@ -247,3 +276,5 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_java_shutdown)
|
|||||||
switch_core_destroy_memory_pool(&memoryPool);
|
switch_core_destroy_memory_pool(&memoryPool);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user