|
1 // Copyright (c) 1997-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 // Abstraction representing a UNIX file descriptor |
|
15 // CFileDescBase maintains the simple semantics of |
|
16 // Dup() and Close(), so the final Close() will |
|
17 // delete the object and hence call the destructor. |
|
18 // |
|
19 // |
|
20 |
|
21 #ifndef _FDESC_H |
|
22 #define _FDESC_H |
|
23 |
|
24 #include <e32std.h> |
|
25 #include <e32cons.h> |
|
26 #include <f32file.h> |
|
27 #include <es_sock.h> |
|
28 #include <c32comm.h> |
|
29 #include <stddef.h> |
|
30 #include <cdblen.h> |
|
31 #include <commdb.h> |
|
32 #include <commdbconnpref.h> |
|
33 #include <sys/stat.h> |
|
34 #include <fcntl.h> |
|
35 #include <rpipe.h> |
|
36 #include <in_sock.h> |
|
37 |
|
38 #include "base.h" |
|
39 #include "StdioClient.h" |
|
40 |
|
41 //FD attributes used internally by the backend |
|
42 const TUint KInvalidFd = 0x00000001; |
|
43 const TUint KMMapedFd = 0x00000002; |
|
44 const TUint KCloseonExec = 0x00000004; |
|
45 const TUint KPipeFd = 0x00000008; |
|
46 const TUint KIoctlOutstanding = 0x00000010; |
|
47 const TUint KConsoleFd = 0x00000020; |
|
48 const TUint KFifoFd = 0x00000030; |
|
49 const TUint KSpawnCloseInChild = 0x00000040; |
|
50 |
|
51 #define SET_CLOSE_ON_EXEC_FLG (1 << 2) |
|
52 |
|
53 #if defined(SYMBIAN_OE_LARGE_FILE_SUPPORT) && !defined(SYMBIAN_OE_NO_LFS) |
|
54 |
|
55 //Large File Support - Use RFile64 and 64 bit file sizes |
|
56 #define RFILE RFile64 |
|
57 #define FSIZE TInt64 |
|
58 |
|
59 #else |
|
60 |
|
61 //No large file support - Use RFile and 32 bit file sizes |
|
62 #define RFILE RFile |
|
63 #define FSIZE TInt |
|
64 |
|
65 #endif //SYMBIAN_OE_LARGE_FILE_SUPPORT && !SYMBIAN_OE_NO_LFS |
|
66 |
|
67 |
|
68 //Enumarations for Polling |
|
69 enum TPollMode |
|
70 { |
|
71 EReadyForReading = 1, |
|
72 EReadyForWriting = 2, |
|
73 EAnyException = 4 |
|
74 }; |
|
75 |
|
76 //Enumarations for Redirection Server |
|
77 enum TRedirConnState |
|
78 { |
|
79 ENotConnected, |
|
80 EConnected, |
|
81 ENoServer |
|
82 }; |
|
83 |
|
84 //Enumerations for the console echo |
|
85 enum TConsoleEcho |
|
86 { |
|
87 EOff = 0, //Turn Off the echo |
|
88 EOn = 1, //Turn On the echo |
|
89 EPrintValid = 33, //Printable ascii character set <33-126> |
|
90 EPrintInvalid=127 |
|
91 }; |
|
92 |
|
93 // The base class for all flavours of FileDescriptor |
|
94 // |
|
95 class CSocketDesc; |
|
96 |
|
97 NONSHARABLE_CLASS(CFileDescBase) : public CBase |
|
98 /* |
|
99 @internalComponent |
|
100 */ |
|
101 { |
|
102 public: |
|
103 |
|
104 static CFileDescBase* Open(const wchar_t* name, int mode, int perms, TInt& err); |
|
105 static CFileDescBase* Socket(RSocketServ& aSs, int family, int style, int protocol, TInt& err); |
|
106 |
|
107 virtual void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
108 virtual TInt ReadCompletion(TDes8& aDesc, TInt aStatus); |
|
109 virtual void ReadCancel(); |
|
110 |
|
111 virtual void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
112 virtual TInt WriteCompletion(TDes8& aDesc, TInt aStatus); |
|
113 virtual void WriteCancel(); |
|
114 virtual TInt SetAtt(TUint aSetAttMask, TUint aClearAttMask); |
|
115 |
|
116 virtual void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); |
|
117 virtual TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus); |
|
118 virtual void IoctlCancel(); |
|
119 |
|
120 virtual void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus); |
|
121 virtual void RecvFromCancel(); |
|
122 |
|
123 virtual void SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen,int flags, TRequestStatus& aStatus); |
|
124 |
|
125 virtual void SendToCancel(); |
|
126 |
|
127 virtual TInt CompletionStatus(TInt& aLength, TInt aStatus); |
|
128 |
|
129 virtual void Sync(TRequestStatus& aStatus); |
|
130 virtual void SyncCancel(); |
|
131 |
|
132 virtual void Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs,TSockAddr *aAddr); |
|
133 virtual void AcceptCancel(); |
|
134 |
|
135 virtual void Connect(const struct sockaddr* aAddr,unsigned long size,TRequestStatus& aStatus); |
|
136 virtual void ConnectCancel(); |
|
137 virtual TBool GetConnectionProgress(); |
|
138 virtual void SetConnectionProgress( TBool aInProgress ); |
|
139 |
|
140 virtual void Shutdown(TUint aHow,TRequestStatus& aStatus); |
|
141 virtual void ShutdownCancel(); |
|
142 |
|
143 virtual TBool TimedRead() {return EFalse;} //default implementation |
|
144 TInt TimeoutValue() const {return iReadTimeout;} |
|
145 |
|
146 virtual TInt LSeek(off_t& offset, int whence); |
|
147 virtual TInt FStat(struct stat* st); |
|
148 virtual TInt Bind(const struct sockaddr* addr, unsigned long size); |
|
149 virtual TInt Listen(TUint qSize); |
|
150 virtual TInt SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize); |
|
151 virtual TInt GetSockOpt(TInt anOptionName,TInt anOptionLevel,TDes8& anOption); |
|
152 virtual TInt SetSockOpt(TInt anOptionName,TInt anOptionLevel,TDesC8& anOption); |
|
153 virtual TInt Fcntl(TUint anArg, TUint aCmd); |
|
154 |
|
155 virtual TInt Poll(TPollMode aMode,TBool& aReadyStatus,TInt& aErrno); |
|
156 virtual TInt Poll(TUint aEvents); |
|
157 virtual TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout); |
|
158 virtual void TweakWatchedEvents(TUint& events); |
|
159 virtual TInt TweakReadyEvents(TInt errval); |
|
160 virtual void CancelNotify(); |
|
161 |
|
162 //Truncate the File |
|
163 virtual TInt Truncate(off_t /*anOffset*/) |
|
164 { |
|
165 return KErrNotSupported; |
|
166 } |
|
167 //Type of the Descriptor |
|
168 virtual TInt Type() |
|
169 { |
|
170 return EBaseDesc; |
|
171 } |
|
172 |
|
173 //Set/reset the Attributes of the FD |
|
174 inline void SetAttributes( TUint32 aBit, TBool aFlag ) |
|
175 { |
|
176 if( aFlag ) |
|
177 { |
|
178 //Set the bit to 1 |
|
179 iFdAttrib |= aBit; |
|
180 } |
|
181 else |
|
182 { |
|
183 //Reset the bit to 0 |
|
184 iFdAttrib &= ~aBit; |
|
185 } |
|
186 } |
|
187 |
|
188 //Get the Attributes of the FD |
|
189 inline const TUint32 Attributes() const |
|
190 { |
|
191 return iFdAttrib; |
|
192 } |
|
193 |
|
194 inline const TUint32 FcntlFlag() const |
|
195 { |
|
196 return iFcntlFlag; |
|
197 } |
|
198 |
|
199 static inline void Cleanup(TAny *aPtr) |
|
200 { |
|
201 ((CFileDescBase*)aPtr)->Close(); |
|
202 } |
|
203 |
|
204 inline void PushLC() |
|
205 { |
|
206 CleanupStack::PushL(TCleanupItem(Cleanup,this)); |
|
207 } |
|
208 |
|
209 IMPORT_C TInt Close(); |
|
210 virtual void UserClose() {return;} |
|
211 inline CFileDescBase* Dup(); |
|
212 inline void SetFid(TInt aFid) { iFid = aFid; } |
|
213 virtual void SetFids(void *aFids); |
|
214 |
|
215 inline void operator delete(TAny *aPtr) __NO_THROW |
|
216 { |
|
217 Backend()->Free(aPtr); |
|
218 } |
|
219 |
|
220 inline void operator delete(TAny *aPtr, TLeave) __NO_THROW |
|
221 { |
|
222 Backend()->Free(aPtr); |
|
223 } |
|
224 |
|
225 inline void operator delete(TAny *aPtr, TAny*) __NO_THROW |
|
226 { |
|
227 Backend()->Free(aPtr); |
|
228 } |
|
229 |
|
230 TBool ReadIsTimed; |
|
231 TBool ReadWasCancelled; |
|
232 |
|
233 protected: |
|
234 CFileDescBase( TUint aFcntl = 0, TUint32 aFdAttrib = 0 ); |
|
235 virtual TInt FinalClose(); |
|
236 static void Complete(TRequestStatus& aStatus, TInt aResult); |
|
237 TInt iReadTimeout; |
|
238 //Used in case of CRedirDesc |
|
239 TInt iFid; |
|
240 //For FD's fcntl |
|
241 TUint iFcntlFlag; |
|
242 //For FD's other attributes |
|
243 TUint32 iFdAttrib; |
|
244 |
|
245 private: |
|
246 //Check if the path corresponds to a directory |
|
247 static TBool CheckIfDirectory(const TDesC& aPath, RFs& aFs); |
|
248 |
|
249 public: |
|
250 enum TDescType |
|
251 { |
|
252 EBaseDesc, |
|
253 EFileDesc, |
|
254 EFileTempDesc, |
|
255 ESocketDesc, |
|
256 ESerialDesc, |
|
257 EDirDesc, |
|
258 ETtyDesc, |
|
259 EPopenPipeDesc, |
|
260 EPipeDesc, |
|
261 ERedirDesc, |
|
262 EStdErrDesc, |
|
263 EFileSocketDesc |
|
264 }; |
|
265 private: |
|
266 TInt iDupCount; |
|
267 public: |
|
268 // Poll is required to return any of the requested events. |
|
269 // In case of any error, "iPollErr" should be checked by the socket-descriptor |
|
270 // to take any corrective action. |
|
271 TInt iPollErr; |
|
272 }; |
|
273 |
|
274 |
|
275 inline CFileDescBase* CFileDescBase::Dup () |
|
276 { iDupCount += 1; return this; } |
|
277 |
|
278 |
|
279 NONSHARABLE_CLASS(CTtyDesc) : public CFileDescBase |
|
280 /* |
|
281 Abstraction of a teletype device, which will be used for |
|
282 the console. |
|
283 @internalComponent |
|
284 */ |
|
285 { |
|
286 public: |
|
287 inline CTtyDesc(CConsoleBase *c); |
|
288 inline CTtyDesc(); |
|
289 ~CTtyDesc(); |
|
290 virtual TInt Type() |
|
291 { |
|
292 return ETtyDesc; |
|
293 } |
|
294 void Read(TDes8& aDesc, TRequestStatus &aStatus); |
|
295 void ReadCancel(); |
|
296 TInt ReadCompletion(TDes8& aDesc, TInt aStatus); |
|
297 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
298 void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); |
|
299 TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus); |
|
300 TInt SetEcho(TUint8 aEcho); |
|
301 protected: |
|
302 virtual TInt FinalClose(); |
|
303 private: |
|
304 void MapCodeAndEcho(TDes8& aDesc, TKeyCode aCode); |
|
305 void CheckConsoleCreated(); |
|
306 void Write(TDes8& aDesc); |
|
307 CConsoleBase *iConsole; |
|
308 //To store last non-modifiable data position and flag for reading data |
|
309 TInt iCurPosX; |
|
310 TInt iCurPosY; |
|
311 TBool iReadingData; |
|
312 TUint8 iEchoVal; |
|
313 }; |
|
314 |
|
315 inline CTtyDesc::CTtyDesc(CConsoleBase *c) : CFileDescBase(), iConsole(c), iEchoVal(EOn){} |
|
316 inline CTtyDesc::CTtyDesc() : CFileDescBase(), iEchoVal(EOn) {} |
|
317 |
|
318 |
|
319 NONSHARABLE_CLASS(CRedirDesc) : public CFileDescBase |
|
320 /* |
|
321 client-side CRedirDesc desc class which will be used to connecting to the Redirection Server |
|
322 @internalComponent |
|
323 */ |
|
324 { |
|
325 public: |
|
326 CRedirDesc(); |
|
327 virtual TInt Type() |
|
328 { |
|
329 return ERedirDesc; |
|
330 } |
|
331 virtual void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
332 virtual void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
333 TInt WriteCompletion(TDes8& aDesc, TInt /*aStatus*/); |
|
334 TInt ReadCompletion(TDes8& aDesc, TInt /*aStatus*/); |
|
335 virtual TInt Fcntl(TUint anArg, TUint aCmd); |
|
336 TInt FinalClose(); |
|
337 TInt Configure(); |
|
338 TInt Poll(TUint aEvents); |
|
339 TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout); |
|
340 TInt TweakReadyEvents(TInt errval); |
|
341 void CancelNotify(); |
|
342 TInt SetEcho(TUint8 aEcho); |
|
343 TBool iReadNone; |
|
344 TBool iWriteNone; |
|
345 private: |
|
346 //Handle to StdioSession |
|
347 RStdioSession iSession; |
|
348 TRedirConnState iStatus; |
|
349 RFastLock iLock; |
|
350 }; |
|
351 |
|
352 |
|
353 NONSHARABLE_CLASS(CStdErrDesc) : public CFileDescBase |
|
354 |
|
355 /* |
|
356 client-side Standard Error desc class which will be used to put all stderr to RDebug::Printf |
|
357 @internalComponent |
|
358 */ |
|
359 { |
|
360 public: |
|
361 CStdErrDesc(); |
|
362 virtual void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
363 TInt WriteCompletion(TDes8& aDesc, TInt /*aStatus*/); |
|
364 virtual TInt Fcntl(TUint anArg, TUint aCmd); |
|
365 virtual TInt Type() |
|
366 { |
|
367 return EStdErrDesc; |
|
368 } |
|
369 }; |
|
370 |
|
371 NONSHARABLE_CLASS(CFileDesc) : public CFileDescBase |
|
372 /* |
|
373 Abstractions for a plain file and a temporary file |
|
374 @internalComponent |
|
375 */ |
|
376 { |
|
377 public: |
|
378 CFileDesc(); |
|
379 ~CFileDesc(); |
|
380 |
|
381 void SetState(const TDes& params); |
|
382 |
|
383 TInt Open(RFs& aSession, const TDesC& aName, int mode, int perms); |
|
384 TInt LSeek(off_t& offset, int whence); |
|
385 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
386 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
387 TInt FStat(struct stat *st); |
|
388 void Sync(TRequestStatus &aStatus); |
|
389 TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus); |
|
390 TInt Fcntl(TUint anArg, TUint aCmd); |
|
391 static void MapStat(struct stat& st, const TTime& aModTime, TUint& aAttr, const mode_t aMode = S_IFREG); |
|
392 TInt Truncate(off_t anOffset); |
|
393 TInt SetAtt(TUint aSetAttMask, TUint aClearAttMask); |
|
394 TInt ProcessLockParams(FSIZE& pos, FSIZE &lock_len, TInt& lock_type, struct flock* anArg); |
|
395 inline int CreateLock() |
|
396 { |
|
397 return iLock.CreateLocal(); |
|
398 } |
|
399 |
|
400 inline RFILE& FileHandle() |
|
401 { |
|
402 return iFile; |
|
403 } |
|
404 |
|
405 inline const FSIZE Offset() const |
|
406 { |
|
407 return iPos; |
|
408 } |
|
409 |
|
410 inline const FSIZE Size() const |
|
411 { |
|
412 return iSize; |
|
413 } |
|
414 inline void setSize(TUint32 param) |
|
415 { |
|
416 iSize = param; |
|
417 } |
|
418 inline const FSIZE Extent() const |
|
419 { |
|
420 return iExt; |
|
421 } |
|
422 virtual TInt Type() |
|
423 { |
|
424 return EFileDesc; |
|
425 } |
|
426 protected: |
|
427 virtual TInt FinalClose(); |
|
428 TInt Alloc(); |
|
429 private: |
|
430 TInt FileRead(TUint8* aPtr,TInt aLength); |
|
431 TInt FileWrite(TUint8* aPtr,TInt aLength); |
|
432 TInt Flush(); |
|
433 TInt DoSync(); |
|
434 TInt DoRead(TDes8& aDesc); |
|
435 TInt DoWrite(TDes8& aDesc); |
|
436 FSIZE Pos(); |
|
437 FSIZE Ext(); |
|
438 |
|
439 private: |
|
440 enum {EAlloc,EReading,EWriting}; |
|
441 enum {EBufferSize = 0x600,EReadAhead = 0x200}; |
|
442 protected: |
|
443 RFILE iFile; |
|
444 TInt16 iDrive; // for use with stat() |
|
445 private: |
|
446 TUint8 iState; |
|
447 TUint8* iBuffer; |
|
448 TUint8* iPtr; |
|
449 TUint8* iEnd; |
|
450 |
|
451 FSIZE iSize; |
|
452 FSIZE iPos; |
|
453 FSIZE iExt; |
|
454 |
|
455 //For locking the descriptor before any operation. |
|
456 //To make it thread safe. |
|
457 RFastLock iLock; |
|
458 friend class RFileDesTransferSession; |
|
459 friend class CFileDesTransferSession; |
|
460 }; |
|
461 |
|
462 NONSHARABLE_CLASS(CTempFileDesc) : public CFileDesc |
|
463 /* |
|
464 @internalComponent |
|
465 */ |
|
466 { |
|
467 public: |
|
468 TInt Open(const wchar_t* aName, TInt mode); |
|
469 virtual TInt Type() |
|
470 { |
|
471 return EFileTempDesc; |
|
472 } |
|
473 protected: |
|
474 virtual TInt FinalClose(); |
|
475 private: |
|
476 RFs iSession; |
|
477 TFileName iName; |
|
478 }; |
|
479 |
|
480 /* |
|
481 Implements common functionality between CSocketDesc and CFileSocketDesc. |
|
482 Not meant to be instantaible. |
|
483 */ |
|
484 NONSHARABLE_CLASS(CSockDescBase) : public CFileDescBase |
|
485 { |
|
486 public: |
|
487 virtual TInt Socket(RSocketServ& aSs, int family, int style, int protocol); |
|
488 TInt Fcntl(TUint anArg, TUint aCmd); |
|
489 TInt FStat(struct stat *st); |
|
490 TInt FinalClose(); |
|
491 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
492 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
493 void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus); |
|
494 void SendTo(TDes8& aDesc, TSockAddr& to, int flags, TRequestStatus& aStatus); |
|
495 TInt Poll(TUint aEvents); |
|
496 TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 aTimeout); |
|
497 void TweakWatchedEvents(TUint& events); |
|
498 TInt TweakReadyEvents(TInt errval); |
|
499 void CancelNotify(); |
|
500 TInt Listen(TUint qSize); |
|
501 void ReadCancel(); |
|
502 TInt ReadCompletion(TDes8& aBuf, TInt aStatus); |
|
503 void RecvFromCancel(); |
|
504 void SendToCancel(); |
|
505 void WriteCancel(); |
|
506 TInt SockName(int anEnd, TSockAddr& anAddr); |
|
507 void Shutdown(TUint aHow,TRequestStatus& aStatus); |
|
508 TInt CompletionStatus(TInt& aLength, TInt aStatus); |
|
509 const TUint& GetSelectEvents() |
|
510 { |
|
511 iIoctlLock.Signal(); |
|
512 return iSelectEvents(); |
|
513 } |
|
514 inline int CreateLock() |
|
515 { |
|
516 return (iIoctlLock.CreateLocal(1)|| iReadLock.CreateLocal() || iWriteLock.CreateLocal()); |
|
517 } |
|
518 inline RSemaphore& GetIoctlLock() |
|
519 { |
|
520 return iIoctlLock; |
|
521 } |
|
522 inline TBool GetConnectionProgress() |
|
523 { |
|
524 return iConnectInProgress; |
|
525 } |
|
526 |
|
527 inline void SetConnectionProgress( TBool aInProgress ) |
|
528 { |
|
529 iConnectInProgress = aInProgress; |
|
530 } |
|
531 |
|
532 protected: |
|
533 //rearrange these |
|
534 CSockDescBase():iAddrFamily(-1),iProtocol(KUndefinedProtocol),iIoctlFlag(EFalse) |
|
535 { |
|
536 |
|
537 } |
|
538 RSocket iSocket; |
|
539 TSockXfrLength iLength; |
|
540 TFileName iPath; |
|
541 TPckgBuf<TUint> iSelectEvents; |
|
542 TInt iAddrFamily; |
|
543 TInt iProtocol; |
|
544 TInt iStyle; |
|
545 // For preventing simultaneous ioctl calls. |
|
546 // No native support. |
|
547 RSemaphore iIoctlLock; |
|
548 TBool iIoctlFlag; |
|
549 |
|
550 //For locking the descriptor before any operation. |
|
551 //To make it thread safe. |
|
552 RFastLock iReadLock; |
|
553 RFastLock iWriteLock; |
|
554 |
|
555 //Flag to mark the connect status of a non-blocking socket as "in progress" |
|
556 //to prevent duplicate connection request |
|
557 TBool iConnectInProgress; |
|
558 protected: |
|
559 |
|
560 inline TInt isStream() const // inline, but private |
|
561 { |
|
562 return iStyle==SOCK_STREAM; |
|
563 } |
|
564 }; |
|
565 |
|
566 NONSHARABLE_CLASS(CSocketDesc) : public CSockDescBase |
|
567 /* |
|
568 Abstraction for a socket |
|
569 @internalComponent |
|
570 */ |
|
571 { |
|
572 public: |
|
573 CSocketDesc(); |
|
574 TInt Socket(RSocketServ& aSs, int family, int style, int protocol); |
|
575 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
576 TInt ReadCompletion (TDes8& /*aBuf*/, TInt aStatus); |
|
577 void ReadCancel(); |
|
578 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
579 void WriteCancel(); |
|
580 void Sync(TRequestStatus& aStatus); |
|
581 void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); |
|
582 TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus); |
|
583 void IoctlCancel(); |
|
584 |
|
585 void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus); |
|
586 void RecvFromCancel(); |
|
587 void SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen, int flags, TRequestStatus& aStatus); |
|
588 |
|
589 void SendToCancel(); |
|
590 |
|
591 void Shutdown(TUint aHow,TRequestStatus& aStatus); |
|
592 void Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs,TSockAddr *aAddr); |
|
593 void AcceptCancel(); |
|
594 void Connect(const struct sockaddr* aAddr,unsigned long size,TRequestStatus& aStatus); |
|
595 void ConnectCancel(); |
|
596 |
|
597 TInt Bind(const struct sockaddr* addr, unsigned long size); |
|
598 TInt Listen(TUint qSize); |
|
599 TInt SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize); |
|
600 TInt GetSockOpt(TInt anOptionName,TInt anOptionLevel,TDes8& anOption); |
|
601 TInt SetSockOpt(TInt anOptionName,TInt anOptionLevel,TDesC8& anOption); |
|
602 TInt Fcntl(TUint anArg, TUint aCmd); |
|
603 |
|
604 TInt Poll(TPollMode aMode,TBool& aReadyStatus,TInt& aErrno); |
|
605 TInt Poll(TUint aEvents); |
|
606 void CancelNotify(); |
|
607 |
|
608 |
|
609 void SetFids(void *aFids); |
|
610 virtual TInt Type() |
|
611 { |
|
612 return ESocketDesc; |
|
613 } |
|
614 |
|
615 protected: |
|
616 TInt FinalClose(); |
|
617 private: |
|
618 |
|
619 TInt GetInterfaceIndex(TUint32 aAddr); |
|
620 TInt GetInterfaceList(void *aParam); |
|
621 TInt GetActiveInterface( void *aParam); |
|
622 TInt GetInterfaceIndexByName(void *aParam); |
|
623 TInt GetActiveInterfaceList(void *aParam); |
|
624 TInt SetInterfaceByName(void *aParam); |
|
625 TInt StartInterface(void *aParam); |
|
626 TInt StartActiveInterface(void *aParam); |
|
627 TInt StopInterface(void *aParam); |
|
628 TInt OpenUsingPreference(); |
|
629 void AccessPointListL(CArrayFixFlat<TAccessPointRecord> *&aRecordPtr, TInt &aLength); |
|
630 void AccessPointCountL(TInt &aCount); |
|
631 void ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord); |
|
632 void OpenIapTableLC(CCommsDatabase **aIapDatabase, CCommsDbTableView **aView); |
|
633 TInt ActiveConnectionCount(TInt &aCount); |
|
634 TInt ActiveConnectionListL(CArrayFixFlat<TAccessPointRecord> *aRecordPtr, TInt &aLength); |
|
635 TInt GetRConnectionDetails(RConnection *aRc, TAccessPointRecord &aApr); |
|
636 TInt StartConnection(void *aParam); |
|
637 TInt GetConnectionPreference(TCommDbConnPref &aApr); |
|
638 void GetIapDetailsByNameL(TBuf<KCommsDbSvrMaxColumnNameLength> aIapName, TAccessPointRecord &aRecord); |
|
639 void StopSubConnection(); |
|
640 void StopConnection(); |
|
641 TInt StartSubConnection(void *aParam); |
|
642 TInt GetInterface(void *Param, TInt aType); |
|
643 TInt GetInterafceNumber(void *aParam); |
|
644 TInt GetIpAddress( void *aParam ); |
|
645 |
|
646 TInt RouteRequest(TInt aReq, void *aParam); |
|
647 TInt GetInterfaceHWAddress(void *aParam); |
|
648 |
|
649 TInt ConvertRtEntry(TSoInetRouteInfo& aRouteInfo, struct rtentry *aRouteEntry); |
|
650 TInt ConvertSockAddr(TInetAddr& aInetAddr, struct sockaddr_in *aSockAddr); |
|
651 |
|
652 TInt GetInterfaceByName(const TDesC& aIfName, TPckgBuf<TSoInetInterfaceInfo>& aIface); |
|
653 TInt Copy(TInetAddr& aDest, TInetAddr& aSrc); |
|
654 |
|
655 TInt GetRemoteIpAddress( void *aParam ); |
|
656 TInt GetInterafceParamInfo( void *aParam,TInt aType); |
|
657 void FindConnectionDetailsL(CArrayFixFlat<TAccessPointRecord>*& aRecordPtr, TInt& aCount); |
|
658 void FindConnectionInfoL(TAccessPointRecord &aRecord,char *ptr); |
|
659 TInt GetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType ); |
|
660 TInt SetInterafceParamInfo( void *aParam,TInt aType); |
|
661 TInt SetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType ); |
|
662 enum InterfaceType |
|
663 { |
|
664 EACCESS_POINT, |
|
665 EACTIVE_CONNECTION, |
|
666 EACTIVE_GETIP, |
|
667 EACCESS_GETMETRIC, |
|
668 EACCESS_GETMTU, |
|
669 EACCESS_GETNETMASK, |
|
670 EACCESS_GETBROADCAST, |
|
671 EACCESS_GETPHYSADDR, |
|
672 EACCESS_GETFLAGS, |
|
673 EACCESS_SETMETRIC, |
|
674 EACCESS_SETMTU, |
|
675 EACCESS_SETFLAGS, |
|
676 EACCESS_SETPHYSADDR, |
|
677 EACTIVE_SETIP, |
|
678 EACCESS_SETNETMASK, |
|
679 EACCESS_SETBROADCAST |
|
680 }; |
|
681 |
|
682 TPtr8 iIoctlBuf; |
|
683 RSocket *iSocketPtr; |
|
684 TAccessPointRecord iConnPref; |
|
685 RConnection iConnection; |
|
686 RConnection *iConnectionPtr; |
|
687 RSubConnection iSubConnection; |
|
688 RSubConnection *iSubConnectionPtr; |
|
689 TInt iRConnectionIndex; |
|
690 RSocketServ *iSockServPtr; |
|
691 void *iFids; |
|
692 |
|
693 }; |
|
694 |
|
695 |
|
696 class CNotifier; |
|
697 |
|
698 NONSHARABLE_CLASS(CSerialDesc) : public CFileDescBase |
|
699 /* |
|
700 @internalComponent |
|
701 */ |
|
702 { |
|
703 |
|
704 friend class CNotifier; |
|
705 |
|
706 public: |
|
707 CSerialDesc() : CFileDescBase(), iReadThreshold(-1), iRequestedSignals(0), |
|
708 iNotifyStatus(NULL), iNotifyParamPtr(NULL) {} |
|
709 |
|
710 TInt Open(const wchar_t* name, int mode, int perms); |
|
711 TInt FinalClose(); |
|
712 |
|
713 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
714 void ReadCancel(); |
|
715 |
|
716 TInt& TimeoutValue() const; |
|
717 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
718 TInt WriteCompletion(TDes8& aDesc, TInt aStatus); |
|
719 |
|
720 |
|
721 void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); |
|
722 TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus); |
|
723 void IoctlCancel(); |
|
724 |
|
725 TBool TimedRead(); |
|
726 void UserClose(); |
|
727 virtual TInt Type() |
|
728 { |
|
729 return ESerialDesc; |
|
730 } |
|
731 |
|
732 protected: |
|
733 |
|
734 private: |
|
735 |
|
736 void NotifyDataAvailable(TRequestStatus& aStatus); |
|
737 void NotifyOutputEmpty(TRequestStatus& aStatus); |
|
738 void NotifyBreak(TRequestStatus& aStatus); |
|
739 void NotifyWriteErrors(TRequestStatus& aStatus, TUint* aRequestParams, TUint aSignalsMask); |
|
740 void NotifySignalChange(TRequestStatus& iStatus, TUint& aRequestParam, TUint aSignalsMask); |
|
741 void NotifyDataAvailableCancel(); |
|
742 void NotifyOutputEmptyCancel(); |
|
743 void NotifyBreakCancel(); |
|
744 void NotifyWriteErrorsCancel(); |
|
745 void NotifySignalChangeCancel(); |
|
746 void Notify(TInt aVal); //complete the notify request |
|
747 TInt NotifiesSupported(); //return the notifies supported at the moment |
|
748 TBool RequestedNotifiesSupported(TInt aRequested); //see if the notifies requested are supported |
|
749 void CancelNotifiers(const CNotifier* aCompletedNotifier); //cancel them all apart from the passed one |
|
750 TUint Signals(); |
|
751 |
|
752 TInt ReadCompletion (TDes8& aBuf, TInt aStatus); |
|
753 |
|
754 TInt iReadThreshold; |
|
755 RComm iCommPort; |
|
756 |
|
757 TInt iRequestedSignals; |
|
758 TRequestStatus* iNotifyStatus; |
|
759 TUint* iNotifyParamPtr; |
|
760 TUint* iRequestDataPtr; |
|
761 |
|
762 CNotifier* iDataAvailableNotifier; |
|
763 CNotifier* iOutputEmptyNotifier; |
|
764 CNotifier* iBreakNotifier; |
|
765 CNotifier* iErrorsNotifier; |
|
766 CNotifier* iSignalsNotifier; |
|
767 |
|
768 }; |
|
769 |
|
770 |
|
771 NONSHARABLE_CLASS(CPipeDescBase) : public CFileDescBase |
|
772 /* |
|
773 Base class with the RPipe handle and common methods |
|
774 @internalComponent |
|
775 */ |
|
776 { |
|
777 public: |
|
778 CPipeDescBase(const TUint16 aMode = 0) : CFileDescBase() |
|
779 { |
|
780 iFdAttrib |= KPipeFd; |
|
781 if (aMode & O_NONBLOCK) |
|
782 { |
|
783 iFcntlFlag |= O_NONBLOCK; |
|
784 } |
|
785 } |
|
786 |
|
787 TInt Fcntl(TUint anArg, TUint aCmd); |
|
788 TInt FStat(struct stat *st); |
|
789 void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); |
|
790 TInt FinalClose(); |
|
791 |
|
792 RPipe& Handle() |
|
793 { |
|
794 return iHandle; |
|
795 } |
|
796 |
|
797 TUint& FcntlFlag() |
|
798 { |
|
799 return iFcntlFlag; |
|
800 } |
|
801 |
|
802 TUint32& FDAttrib() |
|
803 { |
|
804 return iFdAttrib; |
|
805 } |
|
806 virtual TInt Type() |
|
807 { |
|
808 return EPipeDesc; |
|
809 } |
|
810 |
|
811 protected: |
|
812 RPipe iHandle; |
|
813 }; |
|
814 |
|
815 NONSHARABLE_CLASS(CPipeReadDesc) : public CPipeDescBase |
|
816 /* |
|
817 Handle to the read-end of an RPipe object. |
|
818 @internalComponent |
|
819 */ |
|
820 { |
|
821 public: |
|
822 CPipeReadDesc(const TUint16 aMode = 0) : CPipeDescBase(aMode) |
|
823 { |
|
824 iFcntlFlag |= O_RDONLY; |
|
825 } |
|
826 |
|
827 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
828 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
829 TInt Poll(TUint aEvents); |
|
830 TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 /*timeout*/); |
|
831 TInt TweakReadyEvents(TInt errval); |
|
832 void CancelNotify(); |
|
833 |
|
834 protected: |
|
835 TInt DoRead(TDes8& aDesc); |
|
836 }; |
|
837 |
|
838 NONSHARABLE_CLASS(CPipeWriteDesc) : public CPipeDescBase |
|
839 /* |
|
840 Handle to the write-end of an RPipe object. |
|
841 @internalComponent |
|
842 */ |
|
843 { |
|
844 public: |
|
845 CPipeWriteDesc(const TUint16 aMode = 0) : CPipeDescBase(aMode) |
|
846 { |
|
847 iFcntlFlag |= O_WRONLY; |
|
848 } |
|
849 |
|
850 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
851 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
852 TInt Poll(TUint aEvents); |
|
853 TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout); |
|
854 TInt TweakReadyEvents(TInt errval); |
|
855 void CancelNotify(); |
|
856 |
|
857 protected: |
|
858 TInt DoWrite(TDes8& aDesc); |
|
859 }; |
|
860 NONSHARABLE_CLASS(CFileSocketDesc) : public CSockDescBase |
|
861 /* |
|
862 Class representing AF_UNIX socket descriptors |
|
863 Implemented using 2 FIFOs |
|
864 @internalComponent |
|
865 */ |
|
866 { |
|
867 public: |
|
868 CFileSocketDesc(const TUint16 aMode = 0) |
|
869 { |
|
870 if (aMode & O_NONBLOCK) |
|
871 { |
|
872 iFcntlFlag |= O_NONBLOCK; |
|
873 } |
|
874 iFcntlFlag |= O_RDWR; |
|
875 iPath.Zero(); |
|
876 } |
|
877 |
|
878 void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); |
|
879 TInt FinalClose(); |
|
880 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
881 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
882 void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus); |
|
883 void SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen, int flags, TRequestStatus& aStatus); |
|
884 TInt Listen(TUint qSize); |
|
885 TInt GetSockOpt(TInt anOptionName,TInt anOptionLevel,TDes8& anOption); |
|
886 TInt SetSockOpt(TInt anOptionName,TInt anOptionLevel,TDesC8& anOption); |
|
887 TInt Bind(const struct sockaddr* addr, unsigned long size); |
|
888 void Connect(const struct sockaddr* aAddr,unsigned long size, TRequestStatus& aStatus); |
|
889 void Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs, TSockAddr *); |
|
890 TInt Socket(RSocketServ& aSs, int family, int style, int protocol); |
|
891 TInt SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize); |
|
892 void AcceptCancel(); |
|
893 void ConnectCancel(); |
|
894 |
|
895 TUint& FcntlFlag() |
|
896 { |
|
897 return iFcntlFlag; |
|
898 } |
|
899 |
|
900 TUint32& FDAttrib() |
|
901 { |
|
902 return iFdAttrib; |
|
903 } |
|
904 virtual TInt Type() |
|
905 { |
|
906 return EFileSocketDesc; |
|
907 } |
|
908 |
|
909 TInt GetLocalSockAddrByPort(struct sockaddr_un* aAddr,unsigned long* aAddrLen,TUint aPortNum); |
|
910 TInt GetLocalSockPortByPath(const struct sockaddr_un* aAddr,unsigned long aAddrLen,TUint& aPortNum); |
|
911 |
|
912 private: |
|
913 TInt ValidateAddress(const struct sockaddr_un* aAddr,unsigned long* aAddrLen); |
|
914 TInt RemoveLocalSockAddr(); |
|
915 private: |
|
916 TBuf8<KMaxFileName> iPath; |
|
917 RFastLock iReadLock; |
|
918 RFastLock iWriteLock; |
|
919 class TAutoFastLock |
|
920 { |
|
921 public: |
|
922 TAutoFastLock(RFastLock &aLock):iAutoLock(aLock) |
|
923 { |
|
924 iAutoLock.Wait() ; |
|
925 } |
|
926 ~TAutoFastLock() |
|
927 { |
|
928 iAutoLock.Signal() ; |
|
929 } |
|
930 private: |
|
931 RFastLock &iAutoLock; |
|
932 }; |
|
933 }; |
|
934 |
|
935 NONSHARABLE_CLASS(CDirectoryDesc) : public CFileDescBase |
|
936 /* |
|
937 Abstractions for a directory |
|
938 @internalComponent |
|
939 */ |
|
940 { |
|
941 public: |
|
942 CDirectoryDesc(); |
|
943 ~CDirectoryDesc(); |
|
944 |
|
945 TInt Open(RFs& aSession, const TDesC& aName, int mode, int perms); |
|
946 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
947 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
948 TInt Fcntl(TUint anArg, TUint aCmd); |
|
949 TInt LSeek(off_t& offset, int whence); |
|
950 TInt FStat(struct stat *st); |
|
951 //Get the Name of the directory |
|
952 inline const wchar_t* GetDirName() |
|
953 { |
|
954 return (const wchar_t*)iDirName.Ptr(); |
|
955 } |
|
956 virtual TInt Type() |
|
957 { |
|
958 return EDirDesc; |
|
959 } |
|
960 |
|
961 private: |
|
962 RDir iDir; |
|
963 //Name of the directory |
|
964 TFileName iDirName; |
|
965 }; |
|
966 |
|
967 #ifdef SYMBIAN_OE_LIBRT |
|
968 NONSHARABLE_CLASS(CSharedMemDesc) : public CFileDescBase |
|
969 /* |
|
970 Abstractions for shared memory |
|
971 @internalComponent |
|
972 */ |
|
973 { |
|
974 public: |
|
975 CSharedMemDesc(); |
|
976 ~CSharedMemDesc(); |
|
977 |
|
978 TInt Open(const wchar_t* aName, int mode, int perms); |
|
979 void Read(TDes8& aDesc, TRequestStatus& aStatus); |
|
980 void Write(TDes8& aDesc, TRequestStatus& aStatus); |
|
981 TInt Fcntl(TUint anArg, TUint aCmd); |
|
982 TInt FStat(struct stat *st); |
|
983 TInt LSeek(off_t& offset, int whence); |
|
984 private: |
|
985 TInt ShmRead(TUint8* aPtr,TInt aLength); |
|
986 TInt ShmWrite(TUint8* aPtr,TInt aLength); |
|
987 TInt DoShmRead(TDes8& aDesc); |
|
988 TInt DoShmWrite(TDes8& aDesc); |
|
989 TInt Pos(); |
|
990 TInt Ext(); |
|
991 protected: |
|
992 TInt FinalClose(); |
|
993 private: |
|
994 RFastLock iLock; |
|
995 void* iPtr; |
|
996 TInt iSize; |
|
997 TInt iPos; |
|
998 TInt iExt; |
|
999 TInt iPerms; |
|
1000 TInt iKey; |
|
1001 }; |
|
1002 #endif //SYMBIAN_OE_LIBRT |
|
1003 #endif // !_FDESC_H |