stdcpp/include/sysif.h
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef SYSIF_H
       
    21 #define SYSIF_H
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <f32file.h>
       
    25 #include <es_sock.h>
       
    26 #include <c32comm.h>
       
    27 #include <sys/select.h>
       
    28 #include <spawn.h>
       
    29 #include <sys/types.h>
       
    30 #include <wchar.h>
       
    31 #include "ipcclient.h"
       
    32 #include <dirent.h>
       
    33 #include <sys/socket.h>
       
    34 #include <net/if.h>
       
    35 #include <commdb.h>
       
    36 #include <commdbconnpref.h>
       
    37 
       
    38 /*
       
    39 @internalComponent
       
    40 */
       
    41 _LIT(KEstlibInit, "STDLIBS-INIT");
       
    42 
       
    43 _LIT(KFDTransferSvr,"FDTrnsfrSvr");
       
    44 //Forward declaration for references below
       
    45 class RPipe;
       
    46 class CFileDesTransferServer;
       
    47 class RFileDesTransferSession;
       
    48 class CFileDescBase;
       
    49 /* TODO: We don't have to do this in CFileTable. Move to methods */
       
    50 class CFileSocketDesc;
       
    51 
       
    52 struct TChild
       
    53 /*
       
    54 @internalComponent
       
    55 */
       
    56 	{
       
    57 	TInt iFid;
       
    58 	TProcessId iPid;
       
    59 	RProcess iProc;
       
    60 	
       
    61 #ifdef __X86GCC__
       
    62 	// The underlying data for a TProcessId is a TUint64. GCC raises an error if this is intialised to a negative value. Consider changing for all platforms.
       
    63 	TChild(TInt aFid = -1, TProcessId aPid = 0) : iFid(aFid), iPid(aPid)
       
    64 #else
       
    65 	TChild(TInt aFid = -1, TProcessId aPid = -1) : iFid(aFid), iPid(aPid)
       
    66 #endif //__X86GCC__
       
    67 		{
       
    68 		// nada
       
    69 		}
       
    70 
       
    71 #ifdef __X86GCC__
       
    72 	// The underlying data for a TProcessId is a TUint64. GCC raises an error if this is intialised to a negative value. Consider changing for all platforms.
       
    73 	TChild(RProcess &aProc, TProcessId aFid = 0) : iProc(aProc), iFid(aFid)
       
    74 #else
       
    75 	TChild(RProcess &aProc, TProcessId aFid = -1) : iProc(aProc), iFid(aFid)
       
    76 #endif //__X86GCC__
       
    77 		{
       
    78 		iPid = aProc.Id();
       
    79 		}
       
    80 
       
    81 
       
    82 	static TBool MatchByFid(const TChild& aChild1, const TChild& aChild2)
       
    83 		{
       
    84 		if (aChild1.iFid == aChild2.iFid)
       
    85 			{
       
    86 			return ETrue;
       
    87 			}
       
    88 		return EFalse;
       
    89 		}
       
    90 		
       
    91 	static TBool MatchByPid(const TChild& aChild1, const TChild& aChild2)
       
    92 		{
       
    93 		if (aChild1.iPid == aChild2.iPid)
       
    94 			{
       
    95 			return ETrue;
       
    96 			}
       
    97 		return EFalse;
       
    98 		}
       
    99 	};	
       
   100 
       
   101 class TCLSICleanup
       
   102 /*
       
   103 @internalComponent
       
   104 */
       
   105 	{
       
   106 public:
       
   107 	void StorePtrs(RHeap* aHeap, RFs* aFs, RSocketServ* aSs, RCommServ* aCs, RFastLock* aSsLock, RFastLock* aCsLock)
       
   108 		{
       
   109 		iHeap = aHeap;
       
   110 		iFs = aFs;
       
   111 		iSs = aSs;
       
   112 		iCs = aCs;
       
   113 		iSsLock = aSsLock;
       
   114 		iCsLock = aCsLock;
       
   115 		}
       
   116 
       
   117 	~TCLSICleanup()
       
   118 		{
       
   119 		iFs->Close();
       
   120 		iSs->Close();
       
   121 		iSsLock->Close();
       
   122 		iCs->Close();
       
   123 		iCsLock->Close();
       
   124 		iHeap->Close();
       
   125 		}
       
   126 private:
       
   127 	RHeap* iHeap;
       
   128 	RFs* iFs;
       
   129 	RSocketServ* iSs;
       
   130 	RCommServ* iCs;
       
   131 	RFastLock* iSsLock;
       
   132 	RFastLock* iCsLock;
       
   133 	};
       
   134 
       
   135 
       
   136 class TFileTableCleanup
       
   137 {
       
   138 public:
       
   139 	void SaveUserHeap(RHeap* aHeap)
       
   140 		{
       
   141 		iUserHeap = aHeap;
       
   142 		}
       
   143 
       
   144 	~TFileTableCleanup()
       
   145 	{
       
   146 		User::SwitchHeap(iUserHeap);
       
   147 	}
       
   148 
       
   149 private:
       
   150 	RHeap* iUserHeap;
       
   151 };
       
   152 
       
   153 	
       
   154 class CFileTable: public CBase
       
   155 /*
       
   156 @internalComponent
       
   157 */
       
   158 	{
       
   159 public:
       
   160 	CFileTable();
       
   161 	~CFileTable();
       
   162 
       
   163 	TInt Init(RHeap* aHeap = NULL);
       
   164 	void Close();
       
   165 	void Default(CFileDescBase* aRedirMedia, CFileDescBase* aStdErrMedia);
       
   166 	TInt Reserve();
       
   167 	TInt Attach(TInt aFid, CFileDescBase* aFile);
       
   168 	TInt Detach(TInt aFid, CFileDescBase*& aDetached);
       
   169 	TInt At(TInt aFid, CFileDescBase*& aFound) const;
       
   170 	TInt Reserve(TInt aFids[3]);
       
   171 	TInt Detach(TInt aFids[3]);
       
   172 
       
   173 	int dup (int fid, int& anErrno);
       
   174 	int dup2 (int fid1, int fid2, int& anErrno);
       
   175 	int open (const wchar_t* name, int mode, int perms, int& anErrno);
       
   176 	int close (int fid, int& anErrno);
       
   177 	
       
   178 	int UserClose (int fid, int& anErrno);
       
   179 
       
   180 	int lseek (int fid, int offset, int whence, int& anErrno);
       
   181 	int fstat (int fid, struct stat* st, int& anErrno);
       
   182 	int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs);
       
   183 	int listen (int fd, int n, int& anErrno);
       
   184 	int bind (int fd, TSockAddr& address, int& anErrno);
       
   185 	int sockname (int fd, TSockAddr& address, int anEnd, int& anErrno);
       
   186 	int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
       
   187 	int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
       
   188 	int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
       
   189 	int ioctlcancel (int fid, int& anErrno);
       
   190 	int fcntl (int aFid, int aCmd, long anArg, int& anErrno);
       
   191 
       
   192 	TInt Asynch (int fid, CFileDescBase*& aFile);
       
   193 	
       
   194 	int popen (const wchar_t* file, const wchar_t* cmd,const char* mode, int& anErrno);
       
   195 	int pclose (int aFid, int& anErrno);
       
   196 	int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno);
       
   197 	int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno);	
       
   198 	int waitpid (int pid, int* status, int options, int& anErrno);
       
   199 	
       
   200 	int posix_spawn (int* pid, const wchar_t* wpath, 
       
   201 					 const posix_spawn_file_actions_t* file_actions, 
       
   202 					 const posix_spawnattr_t* attrp,
       
   203 					 const wchar_t* wargs, wchar_t** wenvp);
       
   204 
       
   205 	void TransferToChild (RProcess& child, TInt aFds[], TInt aWhich, TInt aSlot);
       
   206 	void PassEnvToChild (RProcess& child, wchar_t** aEnvp);
       
   207 	void PassFileActionsToChild (RProcess& child, 
       
   208 								 const posix_spawn_file_actions_t* aFileActions);
       
   209 	
       
   210 	void CheckOrigins (wchar_t**& wenvp, int& aCount);
       
   211 	TInt InheritFiles(CFileDesTransferServer* server);	
       
   212 	int pipe (int fildes[2], int& anErrno);
       
   213 	int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno, RFs& aFs);
       
   214 	int CreatePipeDesc (int fildes, RPipe& aHandle, TUint16 aMode = 0);
       
   215 	void ClosePipe (int fds[2], int& err);
       
   216 	
       
   217 	static CFileDescBase* FifoOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno);
       
   218 	int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno, RFs& aFs);
       
   219 	static CFileDescBase* LinkOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno, RFs& aFs);	
       
   220 	int unlink (RFs& aFs, const wchar_t *pathName, int& anErrno);
       
   221 	static CFileDescBase* FileSocketOpen(int& anErrno);
       
   222 	int BindFileSocket(int fid, const struct sockaddr_un* addr, int& anErrno, RFs& aFs);
       
   223 	int AcceptFileSocket(CFileSocketDesc* pfs, const struct sockaddr_un* addr, int& anErrno, RFs& aFs);
       
   224 	int ConnectFileSocket(int fid, const struct sockaddr_un* addr, int& anErrno, RFs& aFs);
       
   225 	
       
   226 	TInt RConnectionCount();
       
   227 	TInt RConnectionAt (TInt aRcIndex, RConnection *&aRc);
       
   228 	TInt AddRConnectionPtr (RConnection *aRc, TInt &aRcIndex);
       
   229 	void RemoveRConnectionPtrAt (TInt aRcIndex);	
       
   230 	void DeleteRConnectionList();
       
   231 	
       
   232 	CFileDesTransferServer* NewFDTransferServerL(RSemaphore &sem);
       
   233 	void StartFDTransferServer(CFileDesTransferServer* pServer);
       
   234 	void CloseFDTransferServer(CFileDesTransferServer* pServer);
       
   235 
       
   236 	int SetEcho(int aFd, TUint8 aEcho, int& aErrno);
       
   237 	
       
   238 	void DoTransferAll(RSemaphore &sem,TDesC& name); 
       
   239 	TInt GetFileCount() const
       
   240 		{
       
   241 		return iFids.Count();
       
   242 		}
       
   243 		
       
   244 	void Lock()
       
   245 		{
       
   246 		iFidLock.Wait();
       
   247 		}
       
   248 	
       
   249 	void Unlock()
       
   250 		{
       
   251 		iFidLock.Signal();
       
   252 		}
       
   253 	
       
   254 private:
       
   255 	TFileTableCleanup	iCleanup;
       
   256 	CArrayPtrSeg<CFileDescBase> iFids;
       
   257 	// invoked by dup
       
   258 	TInt Dup(TInt aFid);
       
   259 	// invoked by both dup2 and fcntl with F_DUPFD
       
   260 	TInt Dup2(TInt aFid, TInt aFid2, TBool aCloseFid2);
       
   261 	// the real dup-er.
       
   262     TInt DupFd(TInt aFid1, TInt aFid2);
       
   263 	void Release(TInt aFid);
       
   264 
       
   265 	//Lock for protecting FIDs across threads
       
   266 	RFastLock iFidLock;
       
   267 	
       
   268 	//stores pids of all children of this process
       
   269 	RArray<TChild> iChildren;
       
   270 	
       
   271 	//Methods to manipulate iChildren
       
   272 	void AddChild(const TChild& aChild);
       
   273 	void RemoveChild(TInt aIdx);
       
   274 	
       
   275 	void ExpandFTableL(TInt count);	
       
   276 	
       
   277 	const RArray<TChild>& GetChildren() const
       
   278 		{
       
   279 		return iChildren;
       
   280 		}
       
   281 		
       
   282 	TInt FindChild(const TInt aFid) const
       
   283 		{
       
   284 		return iChildren.Find(TChild(aFid), 
       
   285 							  TIdentityRelation<TChild>(TChild::MatchByFid));
       
   286 		}
       
   287 		
       
   288 	TInt FindChild(const TProcessId aPid) const
       
   289 		{
       
   290 		return iChildren.Find(TChild(-1, aPid), 
       
   291 							  TIdentityRelation<TChild>(TChild::MatchByPid));
       
   292 		}
       
   293 
       
   294 	CArrayPtrSeg<RConnection> iRConnectionList;
       
   295 	//Lock for protecting iRConnectionList across threads
       
   296 	RFastLock iRcLock;
       
   297 	
       
   298 	// A pointer to the private heap
       
   299 	RHeap* iPrivateHeap;
       
   300 	friend class CFileDesTransferSession;
       
   301 	};
       
   302 
       
   303 
       
   304 class PosixFilesystem
       
   305 /*
       
   306 @internalComponent
       
   307 */
       
   308 	{
       
   309 public:
       
   310 	static wchar_t* getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno);
       
   311 	static int chdir (RFs& aFs, const wchar_t* path, int& anErrno);
       
   312 	static int mkdir (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
       
   313 	static int rmdir (RFs& aFs, const wchar_t* path, int& anErrno);
       
   314 	static int chmod (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
       
   315 	static int reg_unlink (RFs& aFs, const wchar_t* path, int& anErrno);
       
   316 	static int stat (RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno);
       
   317 	static int rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno);
       
   318 	static TInt ResolvePath (RFs& aFs, TParse& aResult, const wchar_t* path, TDes* aFilename);
       
   319 	static TInt SetDefaultDir (RFs& aFs);
       
   320 	static int utime (RFs& aFs, const wchar_t* name, const struct utimbuf* filetimes, int& anErrno);
       
   321 	};
       
   322 
       
   323 
       
   324 class TAccessPointRecord
       
   325 	{
       
   326 public:	
       
   327 	TUint32 iId;
       
   328 	TBuf<KCommsDbSvrMaxColumnNameLength> iName;
       
   329 	TUint32 iDialogPref;
       
   330 	TUint32 iDirection;
       
   331 	TUint32 iService;
       
   332 	TBuf<KCommsDbSvrMaxColumnNameLength> iServiceType;
       
   333 	TUint32 iBearer;
       
   334 	TBuf<KCommsDbSvrMaxColumnNameLength> iBearerType;
       
   335 	TUint32 iNetwork;
       
   336 	TUint32 iNetworkWeighting;
       
   337 	TUint32 iLocation;
       
   338 public:
       
   339 	TAccessPointRecord();
       
   340 	
       
   341 	};
       
   342 
       
   343 NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase
       
   344 /*
       
   345 @internalComponent
       
   346 */
       
   347 	{
       
   348 public:
       
   349 
       
   350 	
       
   351 	IMPORT_C CLocalSystemInterface();
       
   352 	IMPORT_C ~CLocalSystemInterface();
       
   353 	
       
   354 #ifdef __SYMBIAN_COMPILE_UNUSED__
       
   355 	CLocalSystemInterface& Clone();
       
   356 	void Release();
       
   357 	void TerminateProcess(int status);
       
   358 #endif //__SYMBIAN_COMPILE_UNUSED__
       
   359 
       
   360 	int AddToDirList(DIR *aDir);
       
   361 	int RemoveDirFromList(DIR* aDir);
       
   362 	int FindInDirList(DIR* aDir);
       
   363 	
       
   364 	void Exit(int code);
       
   365 	
       
   366 	int dup (int fid, int& anErrno);
       
   367 	int dup2 (int fid, int fid2, int& anErrno);
       
   368 	int open (const wchar_t* name, int mode, int perms, int& anErrno);
       
   369 	int read (int fid, char* buf, unsigned long len, int& anErrno);
       
   370 	int write (int fid, const char* buf, unsigned long len, int& anErrno);
       
   371 	int fsync (int fid, int& anErrno);
       
   372 	int close (int fid, int& anErrno);
       
   373 	int lseek (int fid, int offset, int whence, int& anErrno);
       
   374 	int fstat (int fid, struct stat* st, int& anErrno);
       
   375 	int ioctl (int fid, int cmd, void* param, int& anErrno);
       
   376 	int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
       
   377 	int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
       
   378 
       
   379 #ifdef __SYMBIAN_COMPILE_UNUSED__
       
   380 	int ioctl_cancel (int fid, int& anErrno);
       
   381 #endif //__SYMBIAN_COMPILE_UNUSED__
       
   382 
       
   383 	wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno);
       
   384 
       
   385 	int chdir (const wchar_t* path, int& anErrno);
       
   386 	int mkdir (const wchar_t* path, int perms, int& anErrno);
       
   387 	int rmdir (const wchar_t* path, int& anErrno);
       
   388 	int chmod (const wchar_t* path, int perms, int& anErrno);	
       
   389 	int stat (const wchar_t* name, struct stat* st, int& anErrno);
       
   390 	int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno);
       
   391 
       
   392 	IMPORT_C TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename);
       
   393 	int socket (int family, int style, int protocol, int& anErrno);
       
   394 	int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno);
       
   395 	int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno);
       
   396 	int shutdown (int fd, int how, int& anErrno);
       
   397 	int listen (int fd, int n, int& anErrno);
       
   398 	int accept (int fd, struct sockaddr *addr, size_t *size, int& anErrno);
       
   399 	int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
       
   400 	int connect (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
       
   401 	int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno);
       
   402 	int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
       
   403 	int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
       
   404 
       
   405 	int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno);
       
   406 	int waitpid (int pid, int* status, int options, int& anErrno);
       
   407 
       
   408 	int fcntl (int aFid, int aCmd, long anArg, int& anErrno);
       
   409 	int utime (const wchar_t* name, const struct utimbuf* filetimes, int& anErrno);
       
   410 	
       
   411 	int popen (const wchar_t* file, const wchar_t* cmd, const char* mode, int& anErrno);
       
   412 	int pclose (int aFid, int& anErrno);
       
   413 	IMPORT_C void CheckOrigins (wchar_t**& wenvp, int& aCount);
       
   414 	
       
   415     int pipe (int fildes[2], int& anErrno );
       
   416     int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno);
       
   417     int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno );
       
   418     int unlink (const wchar_t *pathName, int& anErrno );
       
   419     
       
   420 	int select (int maxfd, fd_set* readfds,fd_set* writefds,fd_set* exceptfds, struct timeval* tvptr, int& anErrno);
       
   421 	
       
   422 	int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno );
       
   423 	const wchar_t* GetDirName (int aFid);
       
   424 	IMPORT_C int Truncate (int aFid, int anOffset, int& anErrno);
       
   425 	int fchmod (int fd , mode_t  perms, int& anErrno);
       
   426 	
       
   427 	int posix_spawn (int* pid, const wchar_t* wpath, 
       
   428 					 const posix_spawn_file_actions_t* file_actions, 
       
   429 					 const posix_spawnattr_t* attrp,
       
   430 					 const wchar_t* wargs, wchar_t** wenvp);
       
   431 	
       
   432 	int SetEcho(int aFd, TUint8 aEcho, int& aErrno);
       
   433 	
       
   434 	//Set the default interface for network operations
       
   435 	int setdefaultif(const struct ifreq* aIfReq);
       
   436 	
       
   437 	IMPORT_C CFileDescBase* GetDesc(int aFid);
       
   438 	
       
   439 	// functions returning session to File Server
       
   440 	IMPORT_C RFs& FileSession();
       
   441     RCommServ& CommServSession();
       
   442     RSocketServ& SockServSession();
       
   443 
       
   444 	//Dynamic Memory related APIs
       
   445 	IMPORT_C void* Alloc(size_t aNBytes);
       
   446 	IMPORT_C void* ReAlloc(void* aPtr, size_t aNBytes);
       
   447 	IMPORT_C void Free(void* aPtr);
       
   448 	IMPORT_C void* AllocTLD(TInt aSize);
       
   449 	
       
   450 	//Return the private Heap memory
       
   451 	IMPORT_C RHeap* Heap();
       
   452 
       
   453 	//Return the Comms Server Lock
       
   454 	RFastLock& CommsSessionLock();
       
   455 
       
   456 	//Return reference to file table
       
   457 	const CFileTable& FileTable() const;
       
   458 	
       
   459 	//Get the default connection (RConnection) instance 
       
   460 	RConnection& GetDefaultConnection();
       
   461 
       
   462 	static void WaitForNRequest(TRequestStatus aStatusArray[], TInt aNum);
       
   463 
       
   464 private:
       
   465 	//Helper function to read a record from the IAP table
       
   466 	void ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord);
       
   467 	//Get the connection preferences from an IAP name
       
   468 	TInt GetConnectionPreferencesL(TBuf<KCommsDbSvrMaxColumnNameLength> aIapName, 
       
   469 			 					   TCommDbConnPref &aConnPref);
       
   470 	
       
   471 private:
       
   472 	// NOTE: iCleanup should be the first member of CLSI, since iPrivateHeap
       
   473 	// will be destroyed from within iCleanup destructor.
       
   474 	TCLSICleanup	iCleanup;
       
   475 	
       
   476 	CFileTable 		iFids;
       
   477 
       
   478 	RFs 			iFs;
       
   479 	RSocketServ 	iSs;
       
   480 	RCommServ 		iCs;
       
   481 	
       
   482 	//Lock for protecting Socket Session across threads
       
   483 	RFastLock 		iSSLock;
       
   484 	//Lock for protecting Comms Session across threads
       
   485 	RFastLock 		iCSLock;
       
   486 
       
   487 	//Private Heap which will be used by the library for all memory allocation
       
   488 	RHeap* 			iPrivateHeap;
       
   489 	
       
   490 	//used for Opendir
       
   491 	const static TInt KDirGran = 2;
       
   492 	RPointerArray<TAny> iOpenDirList;
       
   493 
       
   494 	//in class consts
       
   495 	const static TInt KTLDInfoListGran = 4;
       
   496 	const static TInt KPtrsGran = 2;
       
   497 
       
   498 	//Thread-TLS pointers mapping
       
   499 	class TTLDInfo
       
   500 		{
       
   501 	public:
       
   502 		TTLDInfo(TThreadId id, TAny* ptr) : iTid(id), iPtrs(CLocalSystemInterface::KPtrsGran)
       
   503 			{
       
   504 			iPtrs.Append(ptr);
       
   505 			}
       
   506 		void Close(RHeap* pHeap)
       
   507 			{
       
   508 			TInt nptrs = iPtrs.Count();
       
   509 			for (TInt j = 0; j < nptrs; ++j)
       
   510 				{
       
   511 				pHeap->Free(iPtrs[j]);
       
   512 				}
       
   513 			iPtrs.Close();
       
   514 			}
       
   515 		TThreadId iTid;
       
   516 		RPointerArray<TAny> iPtrs;
       
   517 		};
       
   518 	
       
   519 	//Array of Thread-TLS pointers mappings
       
   520 	RArray<TTLDInfo> iTLDInfoList;
       
   521 	
       
   522 	//Protect the array from concurrent access
       
   523 	RFastLock	iTLDListLock;
       
   524 
       
   525 	//The default connection to be used for all network apis. 
       
   526 	RConnection iDefConnection;
       
   527 	
       
   528 public:
       
   529 //ipc server session
       
   530 RIpcSession iIpcS;
       
   531 friend class RFileDesTransferSession;
       
   532 	};
       
   533 
       
   534 
       
   535 /*
       
   536 * Return global backend object to libraries
       
   537 */
       
   538 IMPORT_C CLocalSystemInterface* Backend();
       
   539 
       
   540 
       
   541 
       
   542 
       
   543 // LIBC-BACKEND specific Symbian Error Codes
       
   544 const TInt KErrMaxFdOpened = -1025;
       
   545 const TInt KErrDirectoryOpen = -1026;
       
   546 
       
   547 
       
   548 
       
   549 // Directory enumeration
       
   550 
       
   551 NONSHARABLE_STRUCT(__EPOC32_WDIR) : public CBase	// aka "class __EPOC32_WDIR with everything public"
       
   552 	{
       
   553 public:
       
   554 	__EPOC32_WDIR() {}
       
   555 	~__EPOC32_WDIR();
       
   556 
       
   557 	TInt Open();
       
   558 	TInt Open(const TDesC& aPath);
       
   559 	TInt Open(const wchar_t *_path,int*);	
       
   560 	virtual TInt UpdateNarrow();
       
   561 	HBufC* iPath;
       
   562 	CDir* iEntries;
       
   563 	TInt iIndex;		// counting down, 0 means "finished"
       
   564 	struct wdirent iCurrent;
       
   565 	TInt iCount ;
       
   566 	TBuf16<KMaxFileName> iCurrentName;
       
   567 	/* *****************************************************************
       
   568 	Overloading new and delete operators so that they will
       
   569 	allocate and deallocare memory from/to the private heap of backend
       
   570 	********************************************************************/
       
   571 	inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
       
   572 		{
       
   573 		Mem::FillZ(aBase, aSize); return aBase;
       
   574 		}
       
   575 		
       
   576 	inline TAny* operator new(TUint aSize) __NO_THROW
       
   577 		{
       
   578 		return Backend()->Alloc(aSize);
       
   579 		}
       
   580 		
       
   581 	inline TAny* operator new(TUint aSize, TLeave)
       
   582 		{
       
   583 		TAny* ptr = Backend()->Alloc(aSize);
       
   584 		if (ptr == NULL)
       
   585 			{
       
   586 			User::Leave(KErrNoMemory);
       
   587 			}
       
   588 		return ptr;
       
   589 		}
       
   590 		
       
   591 	inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
       
   592 		{
       
   593 		return Backend()->Alloc(aSize + aExtraSize);
       
   594 		}
       
   595 		
       
   596 	inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
       
   597 		{
       
   598 		TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
       
   599 		if (ptr == NULL)
       
   600 			{
       
   601 			User::Leave(KErrNoMemory);
       
   602 			}
       
   603 		return ptr;
       
   604 		}
       
   605 	
       
   606 	inline void operator delete(TAny *aPtr) __NO_THROW
       
   607 		{
       
   608 		Backend()->Free( aPtr );
       
   609 		} 
       
   610 	};
       
   611 	
       
   612 NONSHARABLE_STRUCT(__EPOC32_DIR) : public __EPOC32_WDIR
       
   613 	{
       
   614 public:
       
   615 	__EPOC32_DIR(){}
       
   616 	~__EPOC32_DIR(){}
       
   617 
       
   618 	virtual TInt UpdateNarrow();
       
   619 	struct dirent iCurrentNarrow;
       
   620 	TBuf8<KMaxFileName> iCurrentNarrowName;
       
   621 	};
       
   622 
       
   623 NONSHARABLE_STRUCT (_iconv_t) 
       
   624 	{
       
   625 	TUint toCode;
       
   626 	TUint fromCode;
       
   627 	};
       
   628 
       
   629 class TUSockAddr : public TSockAddr
       
   630 /*
       
   631 Utility class for converting struct sockaddr to and from EPOC32 TSockAddr
       
   632 @internalComponent
       
   633 */
       
   634 	{
       
   635 public:
       
   636 	TUSockAddr() : TSockAddr(), iError(0) {}
       
   637 
       
   638 	TUSockAddr(TAny* addr);			// constructor form of Prepare
       
   639 	IMPORT_C TUSockAddr(const TAny* addr, TUint len);	// constructor form of Set
       
   640 private:
       
   641 	void Prepare(TAny* addr);
       
   642 	void Set(const TAny* addr, TUint len);
       
   643 public:
       
   644 	IMPORT_C void Get(TAny* addr, unsigned long* len);
       
   645 public:
       
   646 	TInt iError; // To store error status of TUSockAddr functions, refers errno.h. Notebly not Symbian error codes.
       
   647 	};
       
   648 	
       
   649 #endif //SYSIF_H
       
   650