赞
踩
这是个聊天内容的类, 这里还对sqlite3数据库进行了操作,已经文件的传输也在这里。
private native long createLinphoneChatMessage(long ptr, String message);
private native long getPeerAddress(long ptr);
private native void sendMessage(long ptr, String message);
private native void sendMessage2(long ptr, Object msg, long messagePtr, StateListener listener);
private native long[] getHistoryRange(long ptr, int begin, int end);
private native long[] getHistory(long ptr, int limit);
private native void destroy(long ptr);
private native int getUnreadMessagesCount(long ptr);
private native int getHistorySize(long ptr);
private native void deleteHistory(long ptr);
private native void compose(long ptr);
private native boolean isRemoteComposing(long ptr);
private native void markAsRead(long ptr);
private native void deleteMessage(long room, long message);
private native long createLinphoneChatMessage2(long ptr, String message,
String url, int state, long timestamp, boolean isRead,
boolean isIncoming);
private native void sendChatMessage(long ptr, Object message, long messagePtr);
private native Object getCore(long nativePtr);
private native long createFileTransferMessage(long ptr, String name, String type, String subtype, int size);
private native Object getCall(long nativePtr);
private native long getChar(long nativePtr);
extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage(JNIEnv* env
,jobject thiz
,jlong ptr
,jstring jmessage) {
const char* message = env->GetStringUTFChars(jmessage, NULL);
LinphoneChatMessage *chatMessage = linphone_chat_room_create_message((LinphoneChatRoom *)ptr, message);
env->ReleaseStringUTFChars(jmessage, message);
return (jlong) chatMessage;
}submodules/linphone/coreapi/chat.c:LinphoneChatMessage *linphone_chat_room_create_message(LinphoneChatRoom *cr, const char *message) {LinphoneChatMessage *linphone_chat_room_create_message(LinphoneChatRoom *cr, const char *message) {
LinphoneChatMessage *msg = belle_sip_object_new(LinphoneChatMessage);
msg->state = LinphoneChatMessageStateIdle;
msg->callbacks = linphone_chat_message_cbs_new();
msg->chat_room = (LinphoneChatRoom *)cr;
msg->message = message ? ms_strdup(message) : NULL;
msg->is_read = TRUE;
msg->content_type = NULL; /* this property is used only when transfering file */
msg->file_transfer_information = NULL; /* this property is used only when transfering file */
msg->http_request = NULL;
msg->time = ms_time(0);
return msg;
}submodules/linphone/coreapi/private.h:struct _LinphoneChatRoom{struct _LinphoneChatRoom{
belle_sip_object_t base;
void *user_data;
struct _LinphoneCore *lc;
char *peer;
LinphoneAddress *peer_url;
MSList *messages_hist;
MSList *transient_messages;
int unread_count;
LinphoneIsComposingState remote_is_composing;
LinphoneIsComposingState is_composing;
belle_sip_source_t *remote_composing_refresh_timer;
belle_sip_source_t *composing_idle_timer;
belle_sip_source_t *composing_refresh_timer;
LinphoneCall *call;
LinphoneChatMessage *pending_message;
MSList *received_rtt_characters;
};
LinphoneChatMessageCbs *linphone_chat_message_cbs_new(void) {
return belle_sip_object_new(LinphoneChatMessageCbs);
}belle_sip_object_new
submodules/belle-sip/include/belle-sip/object.h:BELLESIP_EXPORT belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr);
submodules/belle-sip/include/belle-sip/object.h:#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)BELLE_SIP_OBJECT_GET_VPTR_FUNC(_type)())
extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getPeerAddress(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jlong) linphone_chat_message_get_peer_address((LinphoneChatMessage*)ptr);
}const LinphoneAddress *linphone_chat_message_get_peer_address(LinphoneChatMessage *msg) {
return linphone_chat_room_get_peer_address(msg->chat_room);
}const LinphoneAddress *linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) {
return cr->peer_url;
}extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
,jobject thiz
,jlong ptr
,jstring jmessage) {
const char* message = env->GetStringUTFChars(jmessage, NULL);
linphone_chat_room_send_message((LinphoneChatRoom*)ptr, message);
env->ReleaseStringUTFChars(jmessage, message);
}void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage *msg,
LinphoneChatMessageStateChangedCb status_cb, void *ud) {
msg->message_state_changed_cb = status_cb;
msg->message_state_changed_user_data = ud;
_linphone_chat_room_send_message(cr, msg);
}特像一个回调函数, 先不管他了, 这样吧。
oid _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
/*stubed rtt text*/
if (cr->call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(cr->call))) {
uint32_t new_line = 0x2028;
linphone_chat_message_put_char(msg, new_line); // New Line
linphone_chat_message_set_state(msg, LinphoneChatMessageStateDelivered);
linphone_chat_message_unref(msg);
return;
}
msg->dir = LinphoneChatMessageOutgoing;
// add to transient list
cr->transient_messages = ms_list_append(cr->transient_messages, linphone_chat_message_ref(msg));
/* Check if we shall upload a file to a server */
if (msg->file_transfer_information != NULL && msg->content_type == NULL) {
/* open a transaction with the server and send an empty request(RCS5.1 section 3.5.4.8.3.1) */
linphone_chat_room_upload_file(msg);
} else {
SalOp *op = NULL;
LinphoneCall *call;
char *content_type;
const char *identity = NULL;
msg->time = ms_time(0);
if (lp_config_get_int(cr->lc->config, "sip", "chat_use_call_dialogs", 0) != 0) {
if ((call = linphone_core_get_call_by_remote_address(cr->lc, cr->peer)) != NULL) {
if (call->state == LinphoneCallConnected || call->state == LinphoneCallStreamsRunning ||
call->state == LinphoneCallPaused || call->state == LinphoneCallPausing ||
call->state == LinphoneCallPausedByRemote) {
ms_message("send SIP msg through the existing call.");
op = call->op;
identity = linphone_core_find_best_identity(cr->lc, linphone_call_get_remote_address(call));
}
}
}
if (op == NULL) {
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(cr->lc, cr->peer_url);
if (proxy) {
identity = linphone_proxy_config_get_identity(proxy);
} else
identity = linphone_core_get_primary_contact(cr->lc);
/*sending out of calls*/
msg->op = op = sal_op_new(cr->lc->sal);
linphone_configure_op(cr->lc, op, cr->peer_url, msg->custom_headers,
lp_config_get_int(cr->lc->config, "sip", "chat_msg_with_contact", 0));
sal_op_set_user_pointer(op, msg); /*if out of call, directly store msg*/
}
if (msg->external_body_url) {
content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", msg->external_body_url);
sal_message_send(op, identity, cr->peer, content_type, NULL, NULL);
ms_free(content_type);
} else {
char *peer_uri = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
const char *content_type;
if (linphone_chat_room_lime_enabled(cr)) {
/* ref the msg or it may be destroyed by callback if the encryption failed */
if (msg->content_type && strcmp(msg->content_type, "application/vnd.gsma.rcs-ft-http+xml") == 0) {
/* it's a file transfer, content type shall be set to
application/cipher.vnd.gsma.rcs-ft-http+xml*/
content_type = "application/cipher.vnd.gsma.rcs-ft-http+xml";
} else {
content_type = "xml/cipher";
}
} else {
content_type = msg->content_type;
}
if (content_type == NULL) {
sal_text_send(op, identity, cr->peer, msg->message);
} else {
sal_message_send(op, identity, cr->peer, content_type, msg->message, peer_uri);
}
ms_free(peer_uri);
}
if (msg->from){
/*
* BUG
* the file transfer message constructor sets the from, but doesn't do it as well as here.
*/
linphone_address_destroy(msg->from);
}
msg->from = linphone_address_new(identity);
msg->storage_id = linphone_chat_message_store(msg);
if (cr->unread_count >= 0 && !msg->is_read)
cr->unread_count++;
if (cr->is_composing == LinphoneIsComposingActive) {
cr->is_composing = LinphoneIsComposingIdle;
}
linphone_chat_room_delete_composing_idle_timer(cr);
linphone_chat_room_delete_composing_refresh_timer(cr);
}
// if operation failed, we should not change message state
if (msg->dir == LinphoneChatMessageOutgoing) {
linphone_chat_message_set_state(msg, LinphoneChatMessageStateInProgress);
}
} 
遇见这个么长的一串, 真的不知所错。
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv* env
,jobject thiz
,jlong chatroom_ptr
,jobject message
,jlong messagePtr
,jobject jlistener) {
jobject listener = env->NewGlobalRef(jlistener);
message = env->NewGlobalRef(message);
linphone_chat_message_ref((LinphoneChatMessage*)messagePtr);
linphone_chat_message_set_user_data((LinphoneChatMessage*)messagePtr, message);
linphone_chat_room_send_message2((LinphoneChatRoom*)chatroom_ptr, (LinphoneChatMessage*)messagePtr, chat_room_impl_callback, (void*)listener);
}void linphone_chat_message_set_user_data(LinphoneChatMessage *msg, void *ud) {
msg->message_userdata = ud;
}void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage *msg,
LinphoneChatMessageStateChangedCb status_cb, void *ud) {
msg->message_state_changed_cb = status_cb;
msg->message_state_changed_user_data = ud;
_linphone_chat_room_send_message(cr, msg);
}extern "C" jlongArray Java_org_linphone_core_LinphoneChatRoomImpl_getHistoryRange(JNIEnv* env
,jobject thiz
,jlong ptr
,jint start
,jint end) {
MSList* history = linphone_chat_room_get_history_range((LinphoneChatRoom*)ptr, start, end);
return _LinphoneChatRoomImpl_getHistory(env, thiz, ptr, history);
}submodules/linphone/coreapi/linphonecore_jni.cc:extern "C" jlongArray _LinphoneChatRoomImpl_getHistory(JNIEnv* envextern "C" jlongArray _LinphoneChatRoomImpl_getHistory(JNIEnv* env
,jobject thiz
,jlong ptr
,MSList* history) {
int historySize = ms_list_size(history);
jlongArray jHistory = env->NewLongArray(historySize);
jlong *jInternalArray = env->GetLongArrayElements(jHistory, NULL);
for (int i = 0; i < historySize; i++) {
jInternalArray[i] = (unsigned long) (history->data);
history = history->next;
}
ms_list_free(history);
env->ReleaseLongArrayElements(jHistory, jInternalArray, 0);
return jHistory;
}
extern "C" jint Java_org_linphone_core_LinphoneChatRoomImpl_getUnreadMessagesCount(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jint) linphone_chat_room_get_unread_messages_count((LinphoneChatRoom*)ptr);
}submodules/linphone/coreapi/linphonecore.h:LINPHONE_PUBLIC int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr);
submodules/linphone/coreapi/message_storage.c:int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr){int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr){
return linphone_chat_room_get_messages_count(cr, TRUE);
}static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t unread_only){
LinphoneCore *lc=linphone_chat_room_get_core(cr);
int numrows=0;
char *peer;
char *buf;
sqlite3_stmt *selectStatement;
int returnValue;
if (lc->db==NULL) return 0;
// optimization: do not read database if the count is already available in memory
if(unread_only && cr->unread_count >= 0) return cr->unread_count;
peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
buf=sqlite3_mprintf("SELECT count(*) FROM history WHERE remoteContact = %Q %s;",peer,unread_only?"AND read = 0":"");
returnValue = sqlite3_prepare_v2(lc->db,buf,-1,&selectStatement,NULL);
if (returnValue == SQLITE_OK){
if(sqlite3_step(selectStatement) == SQLITE_ROW){
numrows= sqlite3_column_int(selectStatement, 0);
}
}
sqlite3_finalize(selectStatement);
sqlite3_free(buf);
ms_free(peer);
/* no need to test the sign of cr->unread_count here
* because it has been tested above */
if(unread_only) cr->unread_count = numrows;
return numrows;
}

啊哈, 这里涉及到了sqlite3数据, 太高兴了, 但是怎么兴奋不起来呢。 看完了之后我表示有点看不懂, 也不是真的看不懂, 就是不习惯这样用sqlite3数据库。
extern "C" jint Java_org_linphone_core_LinphoneChatRoomImpl_getHistorySize (JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jint) linphone_chat_room_get_history_size((LinphoneChatRoom*)ptr);
}int linphone_chat_room_get_history_size(LinphoneChatRoom *cr){
return linphone_chat_room_get_messages_count(cr, FALSE);
}static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t unread_only){
LinphoneCore *lc=linphone_chat_room_get_core(cr);
int numrows=0;
char *peer;
char *buf;
sqlite3_stmt *selectStatement;
int returnValue;
if (lc->db==NULL) return 0;
// optimization: do not read database if the count is already available in memory
if(unread_only && cr->unread_count >= 0) return cr->unread_count;
peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
buf=sqlite3_mprintf("SELECT count(*) FROM history WHERE remoteContact = %Q %s;",peer,unread_only?"AND read = 0":"");
returnValue = sqlite3_prepare_v2(lc->db,buf,-1,&selectStatement,NULL);
if (returnValue == SQLITE_OK){
if(sqlite3_step(selectStatement) == SQLITE_ROW){
numrows= sqlite3_column_int(selectStatement, 0);
}
}
sqlite3_finalize(selectStatement);
sqlite3_free(buf);
ms_free(peer);
/* no need to test the sign of cr->unread_count here
* because it has been tested above */
if(unread_only) cr->unread_count = numrows;
return numrows;
}

突然发现,我所看见的这几个函数都是关于sqlite3数据库的, 没有猜错的化, 这里就是专门进行数据库存储的。
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_deleteHistory(JNIEnv* env
,jobject thiz
,jlong ptr) {
linphone_chat_room_delete_history((LinphoneChatRoom*)ptr);
}void linphone_chat_room_delete_history(LinphoneChatRoom *cr){
LinphoneCore *lc=cr->lc;
char *peer;
char *buf;
if (lc->db==NULL) return ;
peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
buf=sqlite3_mprintf("DELETE FROM history WHERE remoteContact = %Q;",peer);
linphone_sql_request(lc->db,buf);
sqlite3_free(buf);
ms_free(peer);
if(cr->unread_count > 0) cr->unread_count = 0;
}int linphone_sql_request(sqlite3* db,const char *stmt){
char* errmsg=NULL;
int ret;
ret=sqlite3_exec(db,stmt,NULL,NULL,&errmsg);
if(ret != SQLITE_OK) {
ms_error("linphone_sql_request: statement %s -> error sqlite3_exec(): %s.", stmt, errmsg);
sqlite3_free(errmsg);
}
return ret;
}JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneChatRoomImpl_compose(JNIEnv *env, jobject thiz, jlong ptr) {
linphone_chat_room_compose((LinphoneChatRoom *)ptr);
}void linphone_chat_room_compose(LinphoneChatRoom *cr) {
int idle_timeout =
lp_config_get_int(cr->lc->config, "sip", "composing_idle_timeout", COMPOSING_DEFAULT_IDLE_TIMEOUT);
int refresh_timeout =
lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT);
if (cr->is_composing == LinphoneIsComposingIdle) {
cr->is_composing = LinphoneIsComposingActive;
linphone_chat_room_send_is_composing_notification(cr);
if (!cr->composing_refresh_timer) {
cr->composing_refresh_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_refresh_composing, cr,
refresh_timeout * 1000, "composing refresh timeout");
} else {
belle_sip_source_set_timeout(cr->composing_refresh_timer, refresh_timeout * 1000);
}
if (!cr->composing_idle_timer) {
cr->composing_idle_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_stop_composing, cr,
idle_timeout * 1000, "composing idle timeout");
}
}
belle_sip_source_set_timeout(cr->composing_idle_timer, idle_timeout * 1000);
}

JNIEXPORT jboolean JNICALL Java_org_linphone_core_LinphoneChatRoomImpl_isRemoteComposing(JNIEnv *env, jobject thiz, jlong ptr) {
return (jboolean)linphone_chat_room_is_remote_composing((LinphoneChatRoom *)ptr);
}bool_t linphone_chat_room_is_remote_composing(const LinphoneChatRoom *cr) {
return (cr->remote_is_composing == LinphoneIsComposingActive) ? TRUE : FALSE;
}extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_markAsRead(JNIEnv* env
,jobject thiz
,jlong ptr) {
linphone_chat_room_mark_as_read((LinphoneChatRoom*)ptr);
}void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){
LinphoneCore *lc=linphone_chat_room_get_core(cr);
int read=1;
char *peer;
char *buf;
if (lc->db==NULL) return ;
// optimization: do not modify the database if no message is marked as unread
if(linphone_chat_room_get_unread_messages_count(cr) == 0) return;
peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
buf=sqlite3_mprintf("UPDATE history SET read=%i WHERE remoteContact = %Q;",
read,peer);
linphone_sql_request(lc->db,buf);
sqlite3_free(buf);
ms_free(peer);
cr->unread_count = 0;
}
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_deleteMessage(JNIEnv* env
,jobject thiz
,jlong room
,jlong msg) {
linphone_chat_room_delete_message((LinphoneChatRoom*)room, (LinphoneChatMessage*)msg);
}void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
LinphoneCore *lc=cr->lc;
char *buf;
if (lc->db==NULL) return ;
buf=sqlite3_mprintf("DELETE FROM history WHERE id = %i;", msg->storage_id);
linphone_sql_request(lc->db,buf);
sqlite3_free(buf);
/* Invalidate unread_count when we modify the database, so that next
time we need it it will be recomputed from latest database state */
cr->unread_count = -1;
}void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
LinphoneCore *lc=cr->lc;
char *buf;
if (lc->db==NULL) return ;
buf=sqlite3_mprintf("DELETE FROM history WHERE id = %i;", msg->storage_id);
linphone_sql_request(lc->db,buf);
sqlite3_free(buf);
/* Invalidate unread_count when we modify the database, so that next
time we need it it will be recomputed from latest database state */
cr->unread_count = -1;
}extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage2(JNIEnv* env
,jobject thiz
,jlong ptr
,jstring jmessage
,jstring jurl
,jint state
,jlong time
,jboolean read
,jboolean incoming) {
const char* message = jmessage?env->GetStringUTFChars(jmessage, NULL):NULL;
const char* url = jurl?env->GetStringUTFChars(jurl, NULL):NULL;
LinphoneChatMessage *chatMessage = linphone_chat_room_create_message_2(
(LinphoneChatRoom *)ptr, message, url, (LinphoneChatMessageState)state,
(time_t)time, read, incoming);
if (jmessage != NULL)
env->ReleaseStringUTFChars(jmessage, message);
if (jurl != NULL)
env->ReleaseStringUTFChars(jurl, url);
return (jlong) chatMessage;
}
LinphoneChatMessage *linphone_chat_room_create_message_2(LinphoneChatRoom *cr, const char *message,
const char *external_body_url, LinphoneChatMessageState state,
time_t time, bool_t is_read, bool_t is_incoming) {
LinphoneChatMessage *msg = linphone_chat_room_create_message(cr, message);
LinphoneCore *lc = linphone_chat_room_get_core(cr);
msg->external_body_url = external_body_url ? ms_strdup(external_body_url) : NULL;
msg->time = time;
msg->is_read = is_read;
linphone_chat_message_set_state(msg, state);
if (is_incoming) {
msg->dir = LinphoneChatMessageIncoming;
linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr));
msg->to = linphone_address_new(linphone_core_get_identity(lc)); /*direct assignment*/
} else {
msg->dir = LinphoneChatMessageOutgoing;
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
msg->from = linphone_address_new(linphone_core_get_identity(lc));/*direct assignment*/
}
return msg;
}
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendChatMessage(JNIEnv* env
,jobject thiz
,jlong chatroom_ptr
,jobject message
,jlong messagePtr) {
message = env->NewGlobalRef(message);
linphone_chat_message_ref((LinphoneChatMessage*)messagePtr);
linphone_chat_message_set_user_data((LinphoneChatMessage*)messagePtr, message);
linphone_chat_room_send_chat_message((LinphoneChatRoom*)chatroom_ptr, (LinphoneChatMessage*)messagePtr);
}LinphoneChatMessage *linphone_chat_message_ref(LinphoneChatMessage *msg) {
belle_sip_object_ref(msg);
return msg;
}void linphone_chat_message_set_user_data(LinphoneChatMessage *msg, void *ud) {
msg->message_userdata = ud;
}void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
_linphone_chat_room_send_message(cr, msg);
}JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneEventImpl_getCore(JNIEnv *env, jobject jobj, jlong evptr){
LinphoneCore *lc=linphone_event_get_core((LinphoneEvent*)evptr);
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc);
jobject core = ljb->getCore();
return core;
}submodules/linphone/coreapi/event.h:LINPHONE_PUBLIC LinphoneCore *linphone_event_get_core(const LinphoneEvent *lev);
submodules/linphone/coreapi/event.c:LinphoneCore *linphone_event_get_core(const LinphoneEvent *lev){submodules/linphone/coreapi/linphonecore.h:LINPHONE_PUBLIC void *linphone_core_get_user_data(const LinphoneCore *lc);
submodules/linphone/coreapi/linphonecore.c:void *linphone_core_get_user_data(const LinphoneCore *lc){extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createFileTransferMessage(JNIEnv* env, jobject thiz, jlong ptr, jstring jname, jstring jtype, jstring jsubtype, jint data_size) {
LinphoneCore *lc = linphone_chat_room_get_core((LinphoneChatRoom*) ptr);
LinphoneContent * content = linphone_core_create_content(lc);
LinphoneChatMessage *message = NULL;
const char *tmp;
linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype, NULL));
env->ReleaseStringUTFChars(jtype, tmp);
linphone_content_set_subtype(content, tmp = env->GetStringUTFChars(jsubtype, NULL));
env->ReleaseStringUTFChars(jsubtype, tmp);
linphone_content_set_name(content, tmp = env->GetStringUTFChars(jname, NULL));
env->ReleaseStringUTFChars(jname, tmp);
linphone_content_set_size(content, data_size);
message = linphone_chat_room_create_file_transfer_message((LinphoneChatRoom *)ptr, content);
linphone_content_unref(content);
return (jlong) message;
}
submodules/linphone/coreapi/linphonecore.h:LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent* initial_content);
submodules/linphone/coreapi/chat_file_transfer.c:LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr,LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr,
const LinphoneContent *initial_content) {
LinphoneChatMessage *msg = belle_sip_object_new(LinphoneChatMessage);
msg->callbacks = linphone_chat_message_cbs_new();
msg->chat_room = (LinphoneChatRoom *)cr;
msg->message = NULL;
msg->is_read = TRUE;
msg->file_transfer_information = linphone_content_copy(initial_content);
msg->dir = LinphoneChatMessageOutgoing;
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
msg->from = linphone_address_new(linphone_core_get_identity(cr->lc)); /*direct assignment*/
/* this will be set to application/vnd.gsma.rcs-ft-http+xml when we will transfer the xml reply from server to the peers */
msg->content_type = NULL;
/* this will store the http request during file upload to the server */
msg->http_request = NULL;
msg->time = ms_time(0);
return msg;
}
extern "C" jobject Java_org_linphone_core_LinphoneChatRoomImpl_getCall(JNIEnv* env ,jobject thiz, jlong ptr) {
return getCall(env, linphone_chat_room_get_call((LinphoneChatRoom *)ptr));
}jobject getCall(JNIEnv *env, LinphoneCall *call){
jobject jobj=0;
if (call!=NULL){
LinphoneCore *lc = linphone_call_get_core(call);
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc);
void *up=linphone_call_get_user_pointer(call);
if (up==NULL){
jobj=env->NewObject(ljb->callClass, ljb->callCtrId, (jlong)call);
jobj=env->NewGlobalRef(jobj);
linphone_call_set_user_pointer(call,(void*)jobj);
linphone_call_ref(call);
}else{
jobj=(jobject)up;
}
}
return jobj;
}
submodules/linphone/coreapi/linphonecore.h:#define linphone_call_get_user_pointer(call) linphone_call_get_user_data(call)extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_getChar(JNIEnv* env ,jobject thiz, jlong ptr) {
return linphone_chat_room_get_char((LinphoneChatRoom *)ptr);
}uint32_t linphone_chat_room_get_char(const LinphoneChatRoom *cr) {
if (cr && cr->received_rtt_characters) {
MSList *characters = cr->received_rtt_characters;
while (characters != NULL) {
LinphoneChatMessageCharacter *cmc = (LinphoneChatMessageCharacter *)characters->data;
if (!cmc->has_been_read) {
cmc->has_been_read = TRUE;
return cmc->value;
}
characters = ms_list_next(characters);
}
}
return 0;
}Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。