|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "debug.h" |
|
17 #include <e32std.h> |
|
18 #include <e32base.h> |
|
19 #include <e32svr.h> |
|
20 #include <f32file.h> |
|
21 #include "tranp.h" |
|
22 #include "tranpprot.h" |
|
23 |
|
24 |
|
25 |
|
26 // |
|
27 // -- IrTranP Configuration definition -- |
|
28 // |
|
29 |
|
30 EXPORT_C TTranpConfig::TTranpConfig() |
|
31 /** Constructor */ |
|
32 { |
|
33 iPMID = KDefaultPMID;// Set Primary Machine ID |
|
34 iSMID = KNullPMID;// Set Secondary NULL |
|
35 } |
|
36 |
|
37 EXPORT_C TTranpConfig::~TTranpConfig() |
|
38 /** Destructor */ |
|
39 { |
|
40 } |
|
41 |
|
42 EXPORT_C void TTranpConfig::SetPrimaryMachine(const TDesC8 &aPMID) |
|
43 /** Sets the primary machine Id. |
|
44 |
|
45 @param aPMID A byte sequence defining the primary machine Id */ |
|
46 { |
|
47 iPMID = aPMID; |
|
48 } |
|
49 |
|
50 EXPORT_C const TDesC8& TTranpConfig::PrimaryMachine() |
|
51 /** Returns the primary machine Id |
|
52 |
|
53 @return A byte sequence defining the primary machine Id */ |
|
54 { |
|
55 return iPMID; |
|
56 } |
|
57 |
|
58 EXPORT_C void TTranpConfig::SetSecondaryMachine(const TDesC8 &aSMID) |
|
59 /** Sets the secondary machine Id. |
|
60 |
|
61 @param aSMID A byte sequence defining the secondary machine Id */ |
|
62 { |
|
63 iSMID = aSMID; |
|
64 } |
|
65 |
|
66 EXPORT_C const TDesC8& TTranpConfig::SecondaryMachine() |
|
67 /** Gets the secondary machine Id |
|
68 |
|
69 @return A byte sequence defining the secondary machine Id */ |
|
70 { |
|
71 return iSMID; |
|
72 } |
|
73 |
|
74 // |
|
75 // -- IrTranP UPF Picture defnition -- |
|
76 // |
|
77 |
|
78 EXPORT_C TTranpPicture::TTranpPicture() : iPicture(KNullDesC8),iThumbNail(KNullDesC8) |
|
79 /** Constructor */ |
|
80 { |
|
81 iUPFPicture = NULL; |
|
82 iX = 1; // Default Aspect Ratio |
|
83 iY = 1; |
|
84 iLatticeSize = EFREE; |
|
85 iHeapData = NULL; |
|
86 } |
|
87 |
|
88 EXPORT_C TTranpPicture::~TTranpPicture() |
|
89 /** Destructor */ |
|
90 { |
|
91 delete iHeapData; |
|
92 } |
|
93 |
|
94 EXPORT_C void TTranpPicture::SetFilename(const TDesC8& aName) |
|
95 /** Sets the file name of the picture in DOS 8.3 format. |
|
96 |
|
97 @param aName The filename in 8.3 format. */ |
|
98 { |
|
99 iFilename = aName; |
|
100 } |
|
101 |
|
102 EXPORT_C const TDesC8& TTranpPicture::Filename() |
|
103 /** Gets the DOS 8.3 format file name of the picture. |
|
104 |
|
105 @return The filename in 8.3 format. */ |
|
106 { |
|
107 return iFilename; |
|
108 } |
|
109 |
|
110 EXPORT_C const TDesC8* TTranpPicture::Picture() |
|
111 /** Gets a pointer to a non-modifiable descriptor containing the image data. |
|
112 The image is in JPEG format. |
|
113 |
|
114 @return A pointer to the image data. */ |
|
115 { |
|
116 return iUPFPicture; |
|
117 } |
|
118 |
|
119 EXPORT_C const TDesC8* TTranpPicture::GetThumbNail() |
|
120 /** Returns a pointer to a descriptor containing a thumbnail representation of |
|
121 the image. The thumbnail is in JPEG format. |
|
122 |
|
123 @return A pointer to the thumbnail data. */ |
|
124 { |
|
125 return NULL; |
|
126 } |
|
127 |
|
128 EXPORT_C void TTranpPicture::SetDesiredLatticeSize(TLatticeSize aSize, TInt /*aWidth*/, TInt /*aHeight*/) |
|
129 { |
|
130 //This will set the desired lattice size. |
|
131 iLatticeSize = aSize; |
|
132 } |
|
133 |
|
134 EXPORT_C void TTranpPicture::GetLatticeSize(TLatticeSize& aSize, TInt& aWidth, TInt& aHeight) |
|
135 { |
|
136 aSize = iLatticeSize; |
|
137 aWidth = iWidth; |
|
138 aHeight = iHeight; |
|
139 } |
|
140 |
|
141 EXPORT_C void TTranpPicture::SetLongFilename(const TDesC8& aName) |
|
142 /** Sets the file name of the picture in SJIS or as an ISO8859-1 character string. |
|
143 |
|
144 @param aName The filename in long format. */ |
|
145 { |
|
146 iLongFilename = aName; |
|
147 } |
|
148 |
|
149 EXPORT_C const TDesC8& TTranpPicture::LongFilename() |
|
150 /** Returns the file name of the picture in SJIS or as an ISO8859-1 character string. |
|
151 |
|
152 @return The filename in long format. */ |
|
153 { |
|
154 return iLongFilename; |
|
155 } |
|
156 |
|
157 EXPORT_C void TTranpPicture::SetTime(const TDesC8& aTime) |
|
158 /** Sets the time stamp attribute iTime to aTime for the picture. |
|
159 |
|
160 @param aTime The time stamp in YYYYMMDDHHMMSS character format. */ |
|
161 { |
|
162 iTime = aTime; |
|
163 } |
|
164 |
|
165 EXPORT_C const TDesC8& TTranpPicture::Time() |
|
166 /** Returns the time stamp attribute for the picture |
|
167 |
|
168 @return iTime The time stamp in YYYYMMDDHHMMSS character format. */ |
|
169 { |
|
170 return iTime; |
|
171 } |
|
172 |
|
173 EXPORT_C TInt TTranpPicture::SaveAsJpeg(const TFileName& aFileName) |
|
174 /** Saves the image data in JPEG format to the specified file on the host device. |
|
175 |
|
176 @param aFileName The name of the file to contain the JPEG format image data. |
|
177 @return KErrNone if successful, otherwise one of the other system wide error |
|
178 codes. */ |
|
179 { |
|
180 TInt err; |
|
181 RFs* fileServer = NULL; |
|
182 RFile* dbgFile = NULL; |
|
183 |
|
184 // Need to stop this from leaving and return error |
|
185 TRAP(err, fileServer = new (ELeave) RFs; |
|
186 dbgFile = new (ELeave) RFile); |
|
187 |
|
188 if (err == KErrNone) |
|
189 { |
|
190 // Connect to Files server |
|
191 err = fileServer->Connect(); |
|
192 if(err == KErrNone) |
|
193 { |
|
194 // Create the file |
|
195 err = dbgFile->Create(*fileServer, aFileName, EFileShareExclusive); |
|
196 if(err == KErrNone) |
|
197 { |
|
198 // Save the file |
|
199 err = dbgFile->Write(iPicture); |
|
200 if(err == KErrNone) |
|
201 { |
|
202 err = dbgFile->Flush(); |
|
203 } |
|
204 } |
|
205 dbgFile->Close(); |
|
206 } |
|
207 fileServer->Close(); |
|
208 } |
|
209 delete dbgFile; |
|
210 delete fileServer; |
|
211 return err; |
|
212 } |
|
213 |
|
214 EXPORT_C TInt TTranpPicture::LoadFromJpeg(const TFileName& /*aFileName*/) |
|
215 /** Loads JPEG format image data from the specified file on the host device. |
|
216 |
|
217 @param aFileName The name of the file containing the JPEG format image data. |
|
218 @return KErrNone if successful, otherwise one of the other system wide error |
|
219 codes. */ |
|
220 { |
|
221 return KErrNotSupported; |
|
222 } |
|
223 |
|
224 EXPORT_C TInt TTranpPicture::SaveAsUPF(const TFileName& aFileName) |
|
225 /** Saves the image data in native UPF format to the specified file on the host |
|
226 device. |
|
227 |
|
228 @param aFileName The name of the file to contain the native UPF format image |
|
229 data. |
|
230 @return KErrNone if successful, otherwise one of the other system wide error |
|
231 codes. */ |
|
232 { |
|
233 TInt err; |
|
234 RFs* fileServer = NULL; |
|
235 RFile* dbgFile = NULL; |
|
236 |
|
237 // Need to stop this from leaving and return error |
|
238 TRAP(err, fileServer = new (ELeave) RFs; |
|
239 dbgFile = new (ELeave) RFile); |
|
240 |
|
241 if (err == KErrNone) |
|
242 { |
|
243 // Connect to Files server |
|
244 err = fileServer->Connect(); |
|
245 if(err == KErrNone) |
|
246 { |
|
247 // Create the file |
|
248 err = dbgFile->Create(*fileServer, aFileName, EFileShareExclusive); |
|
249 if(err == KErrNone) |
|
250 { |
|
251 // Save the file |
|
252 err = dbgFile->Write(*iUPFPicture); |
|
253 if(err == KErrNone) |
|
254 { |
|
255 err = dbgFile->Flush(); |
|
256 } |
|
257 } |
|
258 dbgFile->Close(); |
|
259 } |
|
260 fileServer->Close(); |
|
261 } |
|
262 delete dbgFile; |
|
263 delete fileServer; |
|
264 return err; |
|
265 } |
|
266 |
|
267 EXPORT_C TInt TTranpPicture::LoadFromUPF(const TFileName& /*aFileName*/) |
|
268 /** Loads native UPF format image data from the specified file on the host device. |
|
269 |
|
270 @param aFileName The name of the file containing the native UPF format image |
|
271 data. |
|
272 @return KErrNone if successful, otherwise one of the other system wide error |
|
273 codes. */ |
|
274 { |
|
275 return KErrNotSupported; |
|
276 } |
|
277 |
|
278 CTranpSession::CTranpSession() |
|
279 /** Constructor */ |
|
280 { |
|
281 } |
|
282 |
|
283 EXPORT_C CTranpSession::~CTranpSession() |
|
284 /** Frees all resources owned by the object, prior to its destruction. */ |
|
285 { |
|
286 delete iTranpProtocol; |
|
287 #ifdef _DEBUGTRANP_ |
|
288 RDebug::Close(); |
|
289 #endif |
|
290 } |
|
291 |
|
292 EXPORT_C CTranpSession* CTranpSession::NewL(MTranpNotification& aNotifier) |
|
293 /** Constructs and returns a pointer to a new picture transmission session. |
|
294 |
|
295 @param aNotifier An implementation of the picture transmission callback interface. |
|
296 |
|
297 @return A pointer to the new picture transmission session. */ |
|
298 { |
|
299 DEBUG_OPEN(); |
|
300 SESSIONPRINT(_L("CTranpSession::NewL()\n")); |
|
301 CTranpSession* self = new(ELeave) CTranpSession(); |
|
302 CleanupStack::PushL(self); |
|
303 self->ConstructL(aNotifier); |
|
304 CleanupStack::Pop(); |
|
305 return self; |
|
306 } |
|
307 |
|
308 void CTranpSession::ConstructL(MTranpNotification& aNotifier) |
|
309 { |
|
310 SESSIONPRINT(_L("CTranpSession::ConstructL()\n")); |
|
311 iTranpProtocol = CTranpProtocol::NewL(aNotifier); |
|
312 } |
|
313 |
|
314 EXPORT_C void CTranpSession::Connect() |
|
315 /** Establishes a connection with a peer device. This function is called before |
|
316 sending a picture. |
|
317 |
|
318 The callback function Connect() is called when the connection has been successfully |
|
319 established. |
|
320 |
|
321 @see MTranpNotification::Connected() */ |
|
322 { |
|
323 User::Leave(KErrNotSupported); //Qualified |
|
324 } |
|
325 |
|
326 EXPORT_C void CTranpSession::Disconnect() |
|
327 /** Breaks the connection with a peer device. This function is called after sending |
|
328 a picture. |
|
329 |
|
330 The callback function Disconnected() is called when the connection has been |
|
331 broken. |
|
332 |
|
333 @see MTranpNotification::Connected() */ |
|
334 { |
|
335 User::Leave(KErrNotSupported); //Qualified |
|
336 } |
|
337 |
|
338 EXPORT_C void CTranpSession::Query(TTranP /*aWhat*/) |
|
339 /** Requests information on the processing ability of the peer device. Typically, |
|
340 this is called before sending a picture to that peer device. The information |
|
341 is returned through the callback function QueryComplete(). |
|
342 |
|
343 @param aWhat The specific type of information required from the peer device. |
|
344 @see MTranpNotification::QueryComplete() */ |
|
345 { |
|
346 User::Leave(KErrNotSupported); //Qualified |
|
347 } |
|
348 |
|
349 EXPORT_C void CTranpSession::Abort() |
|
350 /** Aborts any transmission in progress. */ |
|
351 { |
|
352 iTranpProtocol->Abort(); |
|
353 } |
|
354 |
|
355 EXPORT_C void CTranpSession::Get(TTranpPicture& aPicture) |
|
356 /** Receives a picture from a peer device. |
|
357 |
|
358 The following sequence of events is expected: |
|
359 |
|
360 A peer device connects successfully, resulting in a call to the Connect() |
|
361 callback function. |
|
362 |
|
363 The peer device sends picture data, resulting in successive calls to the ProgressIndication() |
|
364 callback function indicating how much of the picture data has been received. |
|
365 |
|
366 Reception of picture data is complete, resulting in a call to the GetComplete() |
|
367 call back function. |
|
368 |
|
369 Disconnection from the peer device, resulting in a call the Disconnected() |
|
370 callback function. |
|
371 |
|
372 If the connection with the peer device is dropped at any stage in the transmission, |
|
373 then this results in a call to the Error() callback function. |
|
374 |
|
375 @param aPicture The picture object |
|
376 @see MTranpNotification::Connected() |
|
377 @see MTranpNotification::ProgressIndication() |
|
378 @see MTranpNotification::GetComplete() |
|
379 @see MTranpNotification::Disconnected() |
|
380 @see MTranpNotification::Error() */ |
|
381 { |
|
382 iTranpProtocol->Get(aPicture); |
|
383 } |
|
384 |
|
385 EXPORT_C void CTranpSession::Put(const TTranpPicture& /*aPicture*/) |
|
386 /** Sends a picture to a peer device. |
|
387 |
|
388 The following sequence of events is expected: |
|
389 |
|
390 This device sends picture data to the peer device, resulting in successive |
|
391 calls to the ProgressIndication() callback function indicating how much of |
|
392 the picture data has been received. |
|
393 |
|
394 Transmission of picture data is complete, resulting in a call to the GetComplete() |
|
395 callback function. |
|
396 |
|
397 If the connection with the peer device is dropped at any stage in the transmission, |
|
398 then this results in a call to the Error() callback function. |
|
399 |
|
400 @param aPicture The picture object |
|
401 @see MTranpNotification::ProgressIndication() |
|
402 @see MTranpNotification::GetComplete() |
|
403 @see MTranpNotification::Error() */ |
|
404 { |
|
405 User::Leave(KErrNotSupported); //Qualified |
|
406 } |
|
407 |
|
408 EXPORT_C void CTranpSession::Config(const TTranpConfig& /*aConfig*/) |
|
409 /** Sets the configuration parameters. |
|
410 |
|
411 @param aConfig The configuration parameters */ |
|
412 { |
|
413 User::Leave(KErrNotSupported); //Qualified |
|
414 } |
|
415 |
|
416 EXPORT_C TTranpConfig CTranpSession::Config() const |
|
417 |
|
418 /** Returns the configuration parameters. |
|
419 |
|
420 @return The configuration parameters. */ |
|
421 { |
|
422 User::Leave(KErrNotSupported); //Qualified |
|
423 return iConfig; |
|
424 } |
|
425 |
|
426 |