javanotify_midp_jsr.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,294 行 · 第 1/3 页
C
1,294 行
/* * * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. *//** * @file * * Implementation of javacall notification functions related to * hardware or service events. */#ifdef __cplusplusextern "C" {#endif#include <string.h>#include <midpServices.h>#include <midp_logging.h>#include <localeMethod.h>#include <midp_jc_event_defs.h>#include <javacall_datagram.h>#include <javacall_events.h>#include <javacall_input.h>#include <javacall_keypress.h>#include <javacall_network.h>#include <javacall_penevent.h>#include <javacall_security.h>#include <javacall_socket.h>#include <javacall_time.h>#include <javautil_unicode.h>#include <javautil_string.h>#include <javacall_memory.h>#include <javacall_lcd.h>#ifdef ENABLE_JSR_120#include <javacall_sms.h>#include <javacall_cbs.h>#endif#ifdef ENABLE_JSR_205#include <javacall_mms.h>#endif#ifdef ENABLE_JSR_177#include <javacall_carddevice.h>#endif#ifdef USE_VSCL#include <javacall_vscl.h>#endif#ifdef ENABLE_JSR_179#include <javanotify_location.h>#endif#ifdef ENABLE_JSR_234#include <javanotify_multimedia_advanced.h>#endif#ifdef ENABLE_ON_DEVICE_DEBUG#include <javacall_odd.h>#endif /* ENABLE_ON_DEVICE_DEBUG */#define MAX_PHONE_NUMBER_LENGTH 48static char selectedNumber[MAX_PHONE_NUMBER_LENGTH];/** * The notification function to be called by platform for keypress * occurences. * The platform will invoke the call back in platform context for * each key press, key release and key repeat occurence * @param key the key that was pressed * @param type <tt>JAVACALL_KEYPRESSED</tt> when key was pressed * <tt>JAVACALL_KEYRELEASED</tt> when key was released * <tt>JAVACALL_KEYREPEATED</tt> when to be called repeatedly * by platform during the duration that the key was held */void javanotify_key_event(javacall_key key, javacall_keypress_type type) { midp_jc_event_union e; REPORT_INFO2(LC_CORE,"javanotify_key_event() >> key=%d , type=%d\n",key,type); e.eventType = MIDP_JC_EVENT_KEY; e.data.keyEvent.key = key; e.data.keyEvent.keyEventType = type; midp_jc_event_send(&e);}/*** The notification function to be called by platform for pen* press/release/drag occurences.* The platform will invoke the call back in platform context for* each pen press, pen release and pen dragg occurence* @param x the x positoin when the pen was pressed/released/dragged* @param y the y positoin when the pen was pressed/released/dragged* @param type <tt>JAVACALL_PENPRESSED</tt> when pen was pressed* <tt>JAVACALL_PENRELEASED</tt> when pen was released* <tt>JAVACALL_PENDRAGGED</tt> when pen was dragged*/void javanotify_pen_event(int x, int y, javacall_penevent_type type) { midp_jc_event_union e; REPORT_INFO3(LC_CORE,"javanotify_pen_event() >> x=%d, y=%d type=%d\n",x,y,type); e.eventType = MIDP_JC_EVENT_PEN; e.data.penEvent.type = type; e.data.penEvent.x = x; e.data.penEvent.y = y; midp_jc_event_send(&e);}void javanotify_alarm_expiration() { midp_jc_event_union e; e.eventType = MIDP_JC_EVENT_PUSH; e.data.pushEvent.alarmHandle = 0; midp_jc_event_send(&e);}/** * A callback function to be called for notification of network * conenction related events, such as network going down or up. * The platform will invoke the call back in platform context. * * @param isInit 0 if the network finalization has been finished, * not 0 - if the initialization * @param status one of PCSL_NET_* completion codes */void jcapp_network_event_received(int isInit, int status) { midp_jc_event_union e; REPORT_INFO(LC_CORE, "jc_network_event() >>\n"); (void)status; e.eventType = MIDP_JC_EVENT_NETWORK; if (isInit) { e.data.networkEvent.netType = MIDP_NETWORK_UP; } else { e.data.networkEvent.netType = MIDP_NETWORK_DOWN; } midp_jc_event_send(&e);}#if ENABLE_JSR_120 #include <jsr120_sms_pool.h> #include <jsr120_cbs_pool.h> #include <javacall_memory.h>#endif#if ENABLE_JSR_205 #include <jsr205_mms_pool.h> #include <string.h>#endif#ifdef ENABLE_JSR_120static SmsMessage* jsr120_sms_new_msg_javacall(jchar encodingType, unsigned char msgAddr[MAX_ADDR_LEN], jchar sourcePortNum, jchar destPortNum, jlong timeStamp, jchar msgLen, unsigned char* msgBuffer) { SmsMessage *sms = (SmsMessage*)javacall_malloc(sizeof(SmsMessage)); memset(sms, 0, sizeof(SmsMessage)); sms->msgAddr = (char*)javacall_malloc(MAX_ADDR_LEN); memset(sms->msgAddr, 0, MAX_ADDR_LEN); sms->msgBuffer = (char*)javacall_malloc(msgLen); memset(sms->msgBuffer, 0, msgLen); sms->encodingType = encodingType; sms->sourcePortNum = sourcePortNum; sms->destPortNum = destPortNum; sms->timeStamp = timeStamp; sms->msgLen = msgLen; if (msgAddr != NULL) { memcpy(sms->msgAddr, msgAddr, MAX_ADDR_LEN); } if (msgBuffer != NULL) { memcpy(sms->msgBuffer, msgBuffer, msgLen); } return sms;}/** * callback that needs to be called by platform to handover an incoming SMS intended for Java * * After this function is called, the SMS message should be removed from platform inbox * * @param msgType JAVACALL_SMS_MSG_TYPE_ASCII, or JAVACALL_SMS_MSG_TYPE_BINARY or JAVACALL_SMS_MSG_TYPE_UNICODE_UCS2 1002 * @param sourceAddress the source SMS address for the message. The format of the address parameter * is expected to be compliant with MSIDN, for example,. +123456789 * @param msgBuffer payload of incoming sms * if msgType is JAVACALL_SMS_MSG_TYPE_ASCII then this is a * pointer to char* ASCII string. * if msgType is JAVACALL_SMS_MSG_TYPE_UNICODE_UCS2, then this * is a pointer to javacall_utf16 UCS-2 string. * if msgType is JAVACALL_SMS_MSG_TYPE_BINARY, then this is a * pointer to binary octet buffer. * @param msgBufferLen payload len of incoming sms * @param sourcePortNum the port number that the message originated from * @param destPortNum the port number that the message was sent to * @param timeStamp SMS service center timestamp */void javanotify_incoming_sms(javacall_sms_encoding msgType, char *sourceAddress, unsigned char *msgBuffer, int msgBufferLen, unsigned short sourcePortNum, unsigned short destPortNum, javacall_int64 timeStamp) { midp_jc_event_union e; SmsMessage* sms; REPORT_INFO(LC_CORE, "javanotify_incoming_sms() >>\n"); e.eventType = MIDP_JC_EVENT_SMS_INCOMING; sms = jsr120_sms_new_msg_javacall( msgType, (unsigned char*)sourceAddress, sourcePortNum, destPortNum, timeStamp, msgBufferLen, msgBuffer); e.data.smsIncomingEvent.stub = (int)sms; midp_jc_event_send(&e); return;}#endif#ifdef ENABLE_JSR_205static char* javacall_copystring(char* src) { int length = strlen(src)+1; char* result = javacall_malloc(length); memcpy(result, src, length); return (char*)result;}static MmsMessage* jsr205_mms_new_msg_javacall(char* fromAddress, char* appID, char* replyToAppID, int msgLen, unsigned char* msgBuffer) { MmsMessage* message = (MmsMessage*)javacall_malloc(sizeof(MmsMessage)); memset(message, 0, sizeof(MmsMessage)); message->fromAddress = javacall_copystring(fromAddress); message->appID = javacall_copystring(appID); message->replyToAppID = javacall_copystring(replyToAppID); message->msgLen = msgLen; if (msgLen > 0) { message->msgBuffer = (char*)memcpy((void*)javacall_malloc(msgLen), msgBuffer, msgLen); } return message;}/* * See javacall_mms.h for description */void javanotify_incoming_mms( char* fromAddress, char* appID, char* replyToAppID, int bodyLen, unsigned char* body) { midp_jc_event_union e; MmsMessage* mms; REPORT_INFO(LC_CORE, "javanotify_incoming_mms() >>\n"); e.eventType = MIDP_JC_EVENT_MMS_INCOMING; mms = jsr205_mms_new_msg_javacall(fromAddress, appID, replyToAppID, bodyLen, body); e.data.mmsIncomingEvent.stub = (int)mms; midp_jc_event_send(&e); return;}void javanotify_incoming_mms_available( char* fromAddress, char* appID, char* replyToAppID, javacall_handle handle) { midp_jc_event_union e; MmsMessage* mms; REPORT_INFO(LC_CORE, "javanotify_incoming_mms_available() >>\n"); e.eventType = MIDP_JC_EVENT_MMS_INCOMING; /*bodyLen=-1*/ mms = jsr205_mms_new_msg_javacall(fromAddress, appID, replyToAppID, -1, (char*)handle); e.data.mmsIncomingEvent.stub = (int)mms; midp_jc_event_send(&e); return;}#endif#ifdef ENABLE_JSR_120static CbsMessage* jsr120_cbs_new_msg_javacall(jchar encodingType, jchar msgID, jchar msgLen, unsigned char* msgBuffer) { CbsMessage* message = (CbsMessage*)javacall_malloc(sizeof(CbsMessage)); memset(message, 0, sizeof(CbsMessage)); message->encodingType = encodingType; message->msgID = msgID; message->msgLen = (msgLen > MAX_CBS_MESSAGE_SIZE) ? MAX_CBS_MESSAGE_SIZE : msgLen; message->msgBuffer = (unsigned char*)javacall_malloc(msgLen); memcpy(message->msgBuffer, msgBuffer, msgLen); return message;}/** * callback that needs to be called by platform to handover an incoming CBS intended for Java * * After this function is called, the CBS message should be removed from platform inbox * * @param msgType JAVACALL_CBS_MSG_TYPE_ASCII, or JAVACALL_CBS_MSG_TYPE_BINARY or JAVACALL_CBS_MSG_TYPE_UNICODE_UCS2 * @param msgID message ID * @param msgBuffer payload of incoming cbs * if msgType is JAVACALL_CBS_MSG_TYPE_ASCII then this is a * pointer to char* ASCII string. * if msgType is JAVACALL_CBS_MSG_TYPE_UNICODE_UCS2, then this * is a pointer to javacall_utf16 UCS-2 string. * if msgType is JAVACALL_CBS_MSG_TYPE_BINARY, then this is a * pointer to binary octet buffer. * @param msgBufferLen payload len of incoming cbs */void javanotify_incoming_cbs( javacall_cbs_encoding msgType, unsigned short msgID, unsigned char* msgBuffer, int msgBufferLen) { midp_jc_event_union e; CbsMessage* cbs; e.eventType = MIDP_JC_EVENT_CBS_INCOMING; REPORT_INFO(LC_CORE, "javanotify_incoming_cbs() >>\n"); cbs = jsr120_cbs_new_msg_javacall(msgType, msgID, msgBufferLen, msgBuffer); e.data.cbsIncomingEvent.stub = (int)cbs; midp_jc_event_send(&e); return;}#endif#ifdef ENABLE_JSR_120/** * A callback function to be called by platform to notify that an SMS * has completed sending operation. * The platform will invoke the call back in platform context for * each sms sending completion. * * @param result indication of send completed status result: Either * <tt>JAVACALL_OK</tt> on success, * <tt>JAVACALL_FAIL</tt> on failure * @param handle Handle value returned from javacall_sms_send */void javanotify_sms_send_completed(javacall_result result, int handle) { midp_jc_event_union e; REPORT_INFO(LC_CORE, "javanotify_sms_send_completed() >>\n"); e.eventType = MIDP_JC_EVENT_SMS_SENDING_RESULT; e.data.smsSendingResultEvent.handle = (void *) handle; e.data.smsSendingResultEvent.result = JAVACALL_OK == result ? WMA_OK : WMA_ERR; midp_jc_event_send(&e); return;}#endif#ifdef ENABLE_JSR_205/** * A callback function to be called by platform to notify that an MMS * has completed sending operation. * The platform will invoke the call back in platform context for * each mms sending completion. * * @param result indication of send completed status result: Either * <tt>JAVACALL_OK</tt> on success, * <tt>JAVACALL_FAIL</tt> on failure * @param handle of available MMS */void javanotify_mms_send_completed(javacall_result result, int handle) { midp_jc_event_union e; REPORT_INFO(LC_CORE, "javanotify_mms_send_completed() >>\n"); e.eventType = MIDP_JC_EVENT_MMS_SENDING_RESULT; e.data.mmsSendingResultEvent.handle = (void *) handle; e.data.mmsSendingResultEvent.result = (JAVACALL_OK == result) ? WMA_OK : WMA_ERR;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?