Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
43dfc703
提交
43dfc703
authored
11月 01, 2012
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-4745 --resolve
上级
efcd5656
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
291 行增加
和
10 行删除
+291
-10
java.conf.xml
conf/vanilla/autoload_configs/java.conf.xml
+4
-9
freeswitch_java.cpp
src/mod/languages/mod_java/freeswitch_java.cpp
+179
-0
freeswitch_java.h
src/mod/languages/mod_java/freeswitch_java.h
+11
-0
mod_java.i
src/mod/languages/mod_java/mod_java.i
+6
-1
ApplicationLauncher.java
...ages/mod_java/src/org/freeswitch/ApplicationLauncher.java
+15
-0
OriginateStateHandler.java
...es/mod_java/src/org/freeswitch/OriginateStateHandler.java
+22
-0
StateHandler.java
...d/languages/mod_java/src/org/freeswitch/StateHandler.java
+54
-0
没有找到文件。
conf/vanilla/autoload_configs/java.conf.xml
浏览文件 @
43dfc703
<configuration
name=
"java.conf"
description=
"Java Plug-Ins"
>
<!-- Path to the Java 1.6 virtual machine to use -->
<javavm
path=
"/usr/java/jdk1.6.0/jre/lib/i386/client/libjvm.so"
/>
<!-- Options to pass to Java -->
<javavm
path=
"/opt/jdk1.6.0_04/jre/lib/amd64/server/libjvm.so"
/>
<options>
<!-- Your class path (make sure freeswitch.jar is on it) -->
<option
value=
"-Djava.class.path=$${base_dir}/scripts/freeswitch.jar"
/>
<!-- Enable remote debugging -->
<option
value=
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000"
/>
<option
value=
"-Djava.class.path=$${base_dir}/scripts/freeswitch.jar:$${base_dir}/scripts/example.jar"
/>
<option
value=
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8000"
/>
</options>
<startup
class=
"net/cog/fs/system/Control"
method=
"startup"
arg=
"start up arg"
/>
<shutdown
class=
"net/cog/fs/system/Control"
method=
"shutdown"
arg=
"shutdown arg"
/>
<startup
class=
"org/freeswitch/example/ApplicationLauncher"
method=
"startup"
/>
</configuration>
src/mod/languages/mod_java/freeswitch_java.cpp
浏览文件 @
43dfc703
#include "freeswitch_java.h"
jobject
originate_state_handler
;
SWITCH_DECLARE
(
void
)
setOriginateStateHandler
(
jobject
stateHandler
)
{
JNIEnv
*
env
=
NULL
;
jint
envStatus
=
javaVM
->
GetEnv
((
void
**
)
&
env
,
JNI_VERSION_1_4
);
if
(
envStatus
!=
JNI_OK
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error getting JNIEnv!
\n
"
);
return
;
}
if
(
stateHandler
!=
NULL
&&
originate_state_handler
!=
NULL
)
{
const
char
*
errorMessage
=
"Originate state handler is already registered"
;
jclass
exceptionClass
=
env
->
FindClass
(
"java/util/TooManyListenersException"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
errorMessage
);
env
->
ThrowNew
(
exceptionClass
,
errorMessage
);
}
else
if
(
stateHandler
==
NULL
&&
originate_state_handler
!=
NULL
)
{
env
->
DeleteGlobalRef
(
originate_state_handler
);
originate_state_handler
=
NULL
;
}
else
{
originate_state_handler
=
env
->
NewGlobalRef
(
stateHandler
);
if
(
originate_state_handler
==
NULL
)
{
const
char
*
errorMessage
=
"Unable to create global reference for state handler"
;
jclass
exceptionClass
=
env
->
FindClass
(
"java/lang/OutOfMemoryError"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
errorMessage
);
env
->
ThrowNew
(
exceptionClass
,
errorMessage
);
}
}
}
JavaSession
::
JavaSession
()
:
CoreSession
()
{
}
...
...
@@ -328,3 +358,152 @@ done:
return
status
;
}
switch_status_t
originate_handler_method
(
switch_core_session_t
*
session
,
const
char
*
method
)
{
if
(
originate_state_handler
!=
NULL
)
{
JNIEnv
*
env
=
NULL
;
bool
needDetach
=
false
;
jint
envStatus
=
javaVM
->
GetEnv
((
void
**
)
&
env
,
JNI_VERSION_1_4
);
if
(
envStatus
==
JNI_EDETACHED
)
{
envStatus
=
javaVM
->
AttachCurrentThread
((
void
**
)
&
env
,
NULL
);
if
(
envStatus
==
JNI_OK
)
needDetach
=
true
;
}
if
(
envStatus
!=
JNI_OK
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error getting JNIEnv!
\n
"
);
return
SWITCH_STATUS_FALSE
;
}
jclass
handlerClass
=
env
->
GetObjectClass
(
originate_state_handler
);
if
(
handlerClass
==
NULL
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error getting handler class!
\n
"
);
if
(
needDetach
)
javaVM
->
DetachCurrentThread
();
return
SWITCH_STATUS_FALSE
;
}
jint
result
=
SWITCH_STATUS_FALSE
;
jmethodID
handlerMethod
=
env
->
GetMethodID
(
handlerClass
,
method
,
"(Ljava/lang/String;)I"
);
if
(
handlerMethod
!=
NULL
)
{
char
*
uuid
=
switch_core_session_get_uuid
(
session
);
jstring
javaUuid
=
env
->
NewStringUTF
(
uuid
);
result
=
env
->
CallIntMethod
(
originate_state_handler
,
handlerMethod
,
javaUuid
);
env
->
DeleteLocalRef
(
javaUuid
);
}
env
->
DeleteLocalRef
(
handlerClass
);
if
(
needDetach
)
javaVM
->
DetachCurrentThread
();
return
(
switch_status_t
)
result
;
}
return
SWITCH_STATUS_FALSE
;
}
switch_status_t
originate_on_init
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onInit"
);
}
switch_status_t
originate_on_routing
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onRouting"
);
}
switch_status_t
originate_on_execute
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onExecute"
);
}
switch_status_t
originate_on_hangup
(
switch_core_session_t
*
session
)
{
if
(
originate_state_handler
!=
NULL
)
{
JNIEnv
*
env
=
NULL
;
bool
needDetach
=
false
;
jint
envStatus
=
javaVM
->
GetEnv
((
void
**
)
&
env
,
JNI_VERSION_1_4
);
if
(
envStatus
==
JNI_EDETACHED
)
{
envStatus
=
javaVM
->
AttachCurrentThread
((
void
**
)
&
env
,
NULL
);
if
(
envStatus
==
JNI_OK
)
needDetach
=
true
;
}
if
(
envStatus
!=
JNI_OK
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error getting JNIEnv!
\n
"
);
return
SWITCH_STATUS_FALSE
;
}
jclass
handlerClass
=
env
->
GetObjectClass
(
originate_state_handler
);
if
(
handlerClass
==
NULL
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error getting handler class!
\n
"
);
if
(
needDetach
)
javaVM
->
DetachCurrentThread
();
return
SWITCH_STATUS_FALSE
;
}
jint
result
=
SWITCH_STATUS_FALSE
;
jmethodID
handlerMethod
=
env
->
GetMethodID
(
handlerClass
,
"onHangup"
,
"(Ljava/lang/String;Ljava/lang/String;)I"
);
if
(
handlerMethod
!=
NULL
)
{
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
const
char
*
uuid
=
switch_core_session_get_uuid
(
session
);
const
char
*
cause
=
switch_channel_cause2str
(
switch_channel_get_cause
(
channel
));
jstring
javaUuid
=
env
->
NewStringUTF
(
uuid
);
jstring
javaCause
=
env
->
NewStringUTF
(
cause
);
result
=
env
->
CallIntMethod
(
originate_state_handler
,
handlerMethod
,
javaUuid
,
javaCause
);
env
->
DeleteLocalRef
(
javaUuid
);
env
->
DeleteLocalRef
(
javaCause
);
}
env
->
DeleteLocalRef
(
handlerClass
);
if
(
needDetach
)
javaVM
->
DetachCurrentThread
();
return
(
switch_status_t
)
result
;
}
return
SWITCH_STATUS_FALSE
;
}
switch_status_t
originate_on_exchange_media
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onExchangeMedia"
);
}
switch_status_t
originate_on_soft_execute
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onSoftExecute"
);
}
switch_status_t
originate_on_consume_media
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onConsumeMedia"
);
}
switch_status_t
originate_on_hibernate
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onHibernate"
);
}
switch_status_t
originate_on_reset
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onReset"
);
}
switch_status_t
originate_on_park
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onPark"
);
}
switch_status_t
originate_on_reporting
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onReporting"
);
}
switch_status_t
originate_on_destroy
(
switch_core_session_t
*
session
)
{
return
originate_handler_method
(
session
,
"onDestroy"
);
}
switch_state_handler_table_t
originate_state_handlers
=
{
/*.on_init */
&
originate_on_init
,
/*.on_routing */
&
originate_on_routing
,
/*.on_execute */
&
originate_on_execute
,
/*.on_hangup */
&
originate_on_hangup
,
/*.on_exchange_media */
&
originate_on_exchange_media
,
/*.on_soft_execute */
&
originate_on_soft_execute
,
/*.on_consume_media */
&
originate_on_consume_media
,
/*.on_hibernate */
&
originate_on_hibernate
,
/*.on_reset */
&
originate_on_reset
,
/*.on_park */
&
originate_on_park
,
/*.on_reporting */
&
originate_on_reporting
,
/*.on_destroy */
&
originate_on_destroy
};
int
JavaSession
::
originate
(
JavaSession
*
aleg
,
char
*
destination
,
int
timeout
)
{
switch_state_handler_table_t
*
stateHandlers
=
NULL
;
if
(
originate_state_handler
!=
NULL
)
stateHandlers
=
&
originate_state_handlers
;
return
CoreSession
::
originate
(
aleg
,
destination
,
timeout
,
stateHandlers
);
}
src/mod/languages/mod_java/freeswitch_java.h
浏览文件 @
43dfc703
...
...
@@ -6,6 +6,16 @@
extern
JavaVM
*
javaVM
;
#ifdef __cplusplus
extern
"C"
{
#endif
SWITCH_DECLARE
(
void
)
setOriginateStateHandler
(
jobject
stateHandler
);
#ifdef __cplusplus
}
#endif
class
JavaSession
:
public
CoreSession
{
public
:
JavaSession
();
...
...
@@ -19,6 +29,7 @@ class JavaSession:public CoreSession {
void
setHangupHook
(
jobject
hangupHook
);
virtual
void
check_hangup_hook
();
virtual
switch_status_t
run_dtmf_callback
(
void
*
input
,
switch_input_type_t
itype
);
int
originate
(
JavaSession
*
aleg
,
char
*
destination
,
int
timeout
);
};
#endif
src/mod/languages/mod_java/mod_java.i
浏览文件 @
43dfc703
...
...
@@ -2,6 +2,7 @@
%include ../../../../swig_common.i
/** insert the following includes into generated code so it compiles */
%{
#include "switch.h"
#include "switch_cpp.h"
#include "freeswitch_java.h"
%}
...
...
@@ -53,7 +54,11 @@
%typemap(javain) char *terminator "$javainput"
%typemap(freearg) char *terminator ""
#define SWITCH_DECLARE(type) type
%javamethodmodifiers CoreSession::originate(CoreSession *, char *, int, switch_state_handler_table_t *) "protected";
%javaexception ("java.util.TooManyListenersException") setOriginateStateHandler(jobject);
%typemap(jtype) jobject stateHandler "org.freeswitch.StateHandler"
%typemap(jstype) jobject stateHandler "org.freeswitch.StateHandler"
%include "enums.swg"
%include switch_swigable_cpp.h
...
...
src/mod/languages/mod_java/src/org/freeswitch/ApplicationLauncher.java
0 → 100644
浏览文件 @
43dfc703
package
org
.
freeswitch
.
example
;
import
org.freeswitch.swig.freeswitch
;
public
class
ApplicationLauncher
{
public
static
final
void
startup
(
String
arg
)
{
try
{
freeswitch
.
setOriginateStateHandler
(
OriginateStateHandler
.
getInstance
());
}
catch
(
Exception
e
)
{
freeswitch
.
console_log
(
"err"
,
"Error registering originate state handler"
);
}
}
}
src/mod/languages/mod_java/src/org/freeswitch/OriginateStateHandler.java
0 → 100644
浏览文件 @
43dfc703
package
org
.
freeswitch
.
example
;
import
org.freeswitch.StateHandler.OnHangupHandler
;
public
class
OriginateStateHandler
implements
OnHangupHandler
{
private
static
OriginateStateHandler
instance
=
null
;
public
static
final
OriginateStateHandler
getInstance
()
{
if
(
instance
==
null
)
instance
=
new
OriginateStateHandler
();
return
instance
;
}
private
OriginateStateHandler
()
{
// hide constructor
}
public
int
onHangup
(
String
uuid
,
String
cause
)
{
return
1
;
// SWITCH_STATUS_FALSE
}
}
\ No newline at end of file
src/mod/languages/mod_java/src/org/freeswitch/StateHandler.java
0 → 100644
浏览文件 @
43dfc703
package
org
.
freeswitch
;
public
interface
StateHandler
{
public
interface
OnInitHandler
extends
StateHandler
{
public
int
onInit
(
String
uuid
);
}
public
static
interface
OnRoutingHandler
extends
StateHandler
{
public
int
onRouting
(
String
uuid
);
}
public
static
interface
OnExecuteHandler
extends
StateHandler
{
public
int
onExecute
(
String
uuid
);
}
public
static
interface
OnHangupHandler
extends
StateHandler
{
public
int
onHangup
(
String
uuid
,
String
cause
);
}
public
static
interface
OnExchangeMediaHandler
extends
StateHandler
{
public
int
onExchangeMedia
(
String
uuid
);
}
public
static
interface
OnSoftExecuteHandler
extends
StateHandler
{
public
int
onSoftExecute
(
String
uuid
);
}
public
static
interface
OnConsumeMediaHandler
extends
StateHandler
{
public
int
onConsumeMedia
(
String
uuid
);
}
public
static
interface
OnHibernateHandler
extends
StateHandler
{
public
int
onHibernate
(
String
uuid
);
}
public
static
interface
OnResetHandler
extends
StateHandler
{
public
int
onReset
(
String
uuid
);
}
public
static
interface
OnParkHandler
extends
StateHandler
{
public
int
onPark
(
String
uuid
);
}
public
static
interface
OnReportingHandler
extends
StateHandler
{
public
int
onReporting
(
String
uuid
);
}
public
static
interface
OnDestroyHandler
extends
StateHandler
{
public
int
onDestroy
(
String
uuid
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论