|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Contains JNI calls made by SocketConnectionImpl |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "com_nokia_mj_impl_socket_SocketConnectionImpl.h" |
|
20 #include "nativesocketconnection.h" |
|
21 |
|
22 |
|
23 using namespace java; |
|
24 |
|
25 JNIEXPORT jint JNICALL |
|
26 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1createNativePeer |
|
27 (JNIEnv *aJni, jobject /*peer*/, jstring aName, jint aMode, jstring aHost, jint aPort) |
|
28 { |
|
29 //LOG1(ESOCKET,EInfo,"host length = %d", (aJni)->GetStringLength(aHost)); |
|
30 const char* host; |
|
31 NativeSocketConnection* nativeConn; |
|
32 const char* name = (aJni)->GetStringUTFChars(aName, 0); |
|
33 |
|
34 if (aHost == NULL) |
|
35 { |
|
36 LOG(ESOCKET,EInfo,"host is null"); |
|
37 host = ""; |
|
38 |
|
39 } |
|
40 else |
|
41 { |
|
42 host = (aJni)->GetStringUTFChars(aHost, 0); |
|
43 } |
|
44 |
|
45 nativeConn = new NativeSocketConnection(name, aMode, host, aPort); |
|
46 |
|
47 // Delete the memory |
|
48 (aJni)->ReleaseStringUTFChars(aName, name); |
|
49 if (aHost != NULL) |
|
50 { |
|
51 (aJni)->ReleaseStringUTFChars(aHost, host); |
|
52 } |
|
53 |
|
54 return reinterpret_cast<jint>(nativeConn); |
|
55 } |
|
56 |
|
57 JNIEXPORT jint JNICALL |
|
58 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1openSocket |
|
59 (JNIEnv *aJni, jobject /*peer*/, jint aNativePeerHandle, jint aSock,jint aType, jint aApn, jintArray aReturnValue) |
|
60 { |
|
61 int err = 0; |
|
62 NativeSocketConnection *nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
63 int ret = nativeConn->socketOpen(aSock,aType,aApn,&err); |
|
64 aJni->SetIntArrayRegion(aReturnValue,0,1,&err); |
|
65 return ret; |
|
66 } |
|
67 |
|
68 JNIEXPORT jint JNICALL |
|
69 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1getport |
|
70 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
71 { |
|
72 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
73 return nativeConn->getPort(); |
|
74 } |
|
75 |
|
76 JNIEXPORT jint JNICALL |
|
77 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1getLocalPort |
|
78 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
79 { |
|
80 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
81 return nativeConn->getLocalPort(); |
|
82 } |
|
83 |
|
84 JNIEXPORT jint JNICALL |
|
85 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1getSocketOption |
|
86 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle, jint aOption) |
|
87 { |
|
88 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
89 return nativeConn->getSocketOption(aOption); |
|
90 } |
|
91 |
|
92 JNIEXPORT jint JNICALL |
|
93 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1setSocketOption |
|
94 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle, jint aOption, jint aValue) |
|
95 { |
|
96 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
97 return nativeConn->setSocketOption(aOption, aValue); |
|
98 } |
|
99 |
|
100 JNIEXPORT jint JNICALL |
|
101 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1getLocalAddress |
|
102 (JNIEnv *aJni, jobject /*peer*/, jint aNativePeerHandle, jobjectArray address) |
|
103 { |
|
104 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
105 char * addr = new char[256]; |
|
106 jint retValue = nativeConn->getLocalAddress(addr); |
|
107 jstring jnistring = aJni->NewStringUTF(addr); |
|
108 aJni->SetObjectArrayElement(address,0,jnistring); |
|
109 aJni->DeleteLocalRef(jnistring); |
|
110 delete[] addr; |
|
111 return retValue; |
|
112 } |
|
113 |
|
114 JNIEXPORT jint JNICALL |
|
115 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1getAddress |
|
116 (JNIEnv *aJni, jobject /*peer*/, jint aNativePeerHandle, jobjectArray address) |
|
117 { |
|
118 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
119 char * addr = new char[256]; |
|
120 jint retValue = nativeConn->getAddress(addr); |
|
121 jstring jnistring = aJni->NewStringUTF(addr); |
|
122 aJni->SetObjectArrayElement(address,0,jnistring); |
|
123 aJni->DeleteLocalRef(jnistring); |
|
124 delete[] addr; |
|
125 return retValue; |
|
126 } |
|
127 |
|
128 |
|
129 JNIEXPORT jint JNICALL |
|
130 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1close |
|
131 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
132 { |
|
133 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
134 return nativeConn->socketClose(); |
|
135 } |
|
136 |
|
137 JNIEXPORT void JNICALL |
|
138 Java_com_nokia_mj_impl_socket_SocketConnectionImpl__1dispose |
|
139 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
140 { |
|
141 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection* >(aNativePeerHandle); |
|
142 delete nativeConn; |
|
143 } |