|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <errno.h> |
|
20 |
|
21 #include "logger.h" |
|
22 #include "mmsconnection.h" |
|
23 #include "mmsserverconnectionfactory.h" |
|
24 |
|
25 namespace java |
|
26 { |
|
27 namespace wma |
|
28 { |
|
29 |
|
30 MmsConnection::MmsConnection(bool aServerConnection,std::wstring aUri) |
|
31 :mUri(aUri), |
|
32 mIsServerConnection(aServerConnection), |
|
33 mReceiveOperation(aServerConnection), |
|
34 mServerConn(0), |
|
35 mMessageMonitor(0), |
|
36 mServerConnectionFactory(0), |
|
37 mMmsPlatformService(0) |
|
38 { |
|
39 JELOG2(EWMA); |
|
40 } |
|
41 |
|
42 void MmsConnection::initialize(JNIEnv& aJni, jobject aPeer) |
|
43 { |
|
44 JELOG2(EWMA); |
|
45 if (mIsServerConnection) |
|
46 { |
|
47 mServerConnectionFactory = &MmsServerConnectionFactory::getFactory(); |
|
48 mServerConn = reinterpret_cast<MmsServerConnection*> |
|
49 (mServerConnectionFactory->create(mUri)); |
|
50 |
|
51 mServerConn->setOpen(); |
|
52 mMessageMonitor = java::util::Monitor::createMonitor(); |
|
53 } |
|
54 mMmsPlatformService = MMSPlatformService::getInstance(aJni, aPeer, |
|
55 mIsServerConnection, mUri, this); |
|
56 |
|
57 } |
|
58 |
|
59 void MmsConnection::msgArrived(const std::wstring&) |
|
60 { |
|
61 JELOG2(EWMA); |
|
62 mMessageMonitor->notify(); |
|
63 } |
|
64 |
|
65 void MmsConnection::error(const std::wstring& /*aUri*/, int /*aErrCode*/, |
|
66 const std::string& /*aErrText*/) |
|
67 { |
|
68 // This is not handled |
|
69 } |
|
70 |
|
71 void MmsConnection::open(JNIEnv& aJni, jobject aPeer) |
|
72 { |
|
73 JELOG2(EWMA); |
|
74 int status =0; |
|
75 int messages = 0; |
|
76 int newMessages = 0; |
|
77 int messagesNotified = 0; |
|
78 jclass sessionClass = aJni.FindClass( |
|
79 "com/nokia/mj/impl/mms/MMSConnectionImpl"); |
|
80 jmethodID receiveCallBackMethodId = aJni.GetMethodID(sessionClass, |
|
81 "messageReceiveCallback", "(I)I"); |
|
82 // Keep notifying the java side about incoming messages till |
|
83 // the connection is closed |
|
84 while (mReceiveOperation && (0 == status)) |
|
85 { |
|
86 // waits for the notification from server connection |
|
87 mMessageMonitor->wait(); |
|
88 // check whether its a message notification or connection close |
|
89 // notification |
|
90 if (mReceiveOperation) |
|
91 { |
|
92 // Get no of messages available in store |
|
93 messages = mMmsPlatformService->getNumberOfMessages(); |
|
94 // Calculate no of new messages to be notified to java |
|
95 newMessages = messages - messagesNotified; |
|
96 messagesNotified = messages; |
|
97 if (newMessages > 0) |
|
98 { |
|
99 status = aJni.CallIntMethod(aPeer, receiveCallBackMethodId, |
|
100 newMessages); |
|
101 } |
|
102 newMessages = 0; |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 void MmsConnection::close(JNIEnv& aJni, jobject aPeer) |
|
108 { |
|
109 JELOG2(EWMA); |
|
110 if (mIsServerConnection) |
|
111 { |
|
112 mReceiveOperation = false; |
|
113 if (0 != mMessageMonitor) |
|
114 { |
|
115 mMessageMonitor->notify(); |
|
116 } |
|
117 if ((0 != mServerConnectionFactory) && (0 != mServerConn)) |
|
118 { |
|
119 mServerConnectionFactory->releaseConnection(mUri); |
|
120 mServerConnectionFactory = 0; |
|
121 mServerConn = 0; |
|
122 } |
|
123 } |
|
124 if (0 != mMmsPlatformService) |
|
125 { |
|
126 mMmsPlatformService->closeConnection(aJni, aPeer); |
|
127 } |
|
128 } |
|
129 |
|
130 jint MmsConnection::sendMMS(JNIEnv& aJni, jbyteArray aMsg, jint aOffset, |
|
131 jint aMsgLenght, jstring aAddress) |
|
132 { |
|
133 JELOG2(EWMA); |
|
134 return mMmsPlatformService->send(aJni, aMsg, aOffset, aMsgLenght, aAddress); |
|
135 } |
|
136 |
|
137 jbyteArray MmsConnection::retrieveMMSMessage(JNIEnv& aJni) |
|
138 { |
|
139 JELOG2(EWMA); |
|
140 return mMmsPlatformService->retrieveMessage(aJni); |
|
141 } |
|
142 |
|
143 MmsConnection::~MmsConnection() |
|
144 { |
|
145 JELOG2(EWMA); |
|
146 delete mMmsPlatformService; |
|
147 delete mMessageMonitor; |
|
148 } |
|
149 |
|
150 } //namespace wma |
|
151 } //namespace java |