genericopenlibs/openenvcore/backend/inc/sysif.h
changeset 0 e4d67989cc36
child 3 18f64da82512
child 18 47c74d1534e1
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1998-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 #ifndef SYSIF_H
       
    20 #define SYSIF_H
       
    21 #include <e32std.h>
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <es_sock.h>
       
    25 #include <c32comm.h>
       
    26 #include <sys/select.h>
       
    27 #include <spawn.h>
       
    28 #include <sys/types.h>
       
    29 #include <wchar.h>
       
    30 #include "ipcclient.h"
       
    31 #include <dirent.h>
       
    32 #include <sys/socket.h>
       
    33 #include <stdapis/net/if.h>
       
    34 #include <commdb.h>
       
    35 #include <commdbconnpref.h>
       
    36 #include <rpipe.h>
       
    37 
       
    38 #ifdef SYMBIAN_OE_POSIX_SIGNALS
       
    39 #include "signalclient.h"
       
    40 #include "tsignalmessage.h"
       
    41 
       
    42 typedef void (*TSignalHandler)(int);
       
    43 typedef void (*TSignalAction)(int, siginfo_t *, void *);
       
    44 #endif
       
    45 
       
    46 /*
       
    47 @internalComponent
       
    48 */
       
    49 _LIT(KEstlibInit, "STDLIBS-INIT");
       
    50 
       
    51 _LIT(KFDTransferSvr,"FDTrnsfrSvr");
       
    52 //Forward declaration for references below
       
    53 class RPipe;
       
    54 class CFileDesTransferServer;
       
    55 class RFileDesTransferSession;
       
    56 class CFileDescBase;
       
    57 /* TODO: We don't have to do this in CFileTable. Move to methods */
       
    58 class CFileSocketDesc;
       
    59 
       
    60 struct TChild
       
    61 /*
       
    62 @internalComponent
       
    63 */
       
    64 	{
       
    65 	TInt iFid;
       
    66 	TProcessId iPid;
       
    67 	RProcess iProc;
       
    68 
       
    69 #ifdef __X86GCC__
       
    70 	// 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.
       
    71 	TChild(TInt aFid = -1, TProcessId aPid = 0) : iFid(aFid), iPid(aPid)
       
    72 #else
       
    73 	TChild(TInt aFid = -1, TProcessId aPid = -1) : iFid(aFid), iPid(aPid)
       
    74 #endif //__X86GCC__
       
    75 		{
       
    76 		// nada
       
    77 		}
       
    78 
       
    79 #ifdef __X86GCC__
       
    80 	// 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.
       
    81 	TChild(RProcess &aProc, TProcessId aFid = 0) : iProc(aProc), iFid(aFid)
       
    82 #else
       
    83 	TChild(RProcess &aProc, TProcessId aFid = -1) : iProc(aProc), iFid(aFid)
       
    84 #endif //__X86GCC__
       
    85 		{
       
    86 		iPid = aProc.Id();
       
    87 		}
       
    88 
       
    89 
       
    90 	static TBool MatchByFid(const TChild& aChild1, const TChild& aChild2)
       
    91 		{
       
    92 		if (aChild1.iFid == aChild2.iFid)
       
    93 			{
       
    94 			return ETrue;
       
    95 			}
       
    96 		return EFalse;
       
    97 		}
       
    98 
       
    99 	static TBool MatchByPid(const TChild& aChild1, const TChild& aChild2)
       
   100 		{
       
   101 		if (aChild1.iPid == aChild2.iPid)
       
   102 			{
       
   103 			return ETrue;
       
   104 			}
       
   105 		return EFalse;
       
   106 		}
       
   107 	};
       
   108 
       
   109 class TCLSICleanup
       
   110 /*
       
   111 @internalComponent
       
   112 */
       
   113 	{
       
   114 public:
       
   115 	void StorePtrs(RHeap* aHeap, RFs* aFs, RSocketServ* aSs, RCommServ* aCs, RFastLock* aSsLock, RFastLock* aCsLock)
       
   116 		{
       
   117 		iHeap = aHeap;
       
   118 		iFs = aFs;
       
   119 		iSs = aSs;
       
   120 		iCs = aCs;
       
   121 		iSsLock = aSsLock;
       
   122 		iCsLock = aCsLock;
       
   123 		}
       
   124 
       
   125 	~TCLSICleanup()
       
   126 		{
       
   127 		iFs->Close();
       
   128 		iSs->Close();
       
   129 		iSsLock->Close();
       
   130 		iCs->Close();
       
   131 		iCsLock->Close();
       
   132 		iHeap->Close();
       
   133 		}
       
   134 private:
       
   135 	RHeap* iHeap;
       
   136 	RFs* iFs;
       
   137 	RSocketServ* iSs;
       
   138 	RCommServ* iCs;
       
   139 	RFastLock* iSsLock;
       
   140 	RFastLock* iCsLock;
       
   141 	};
       
   142 
       
   143 
       
   144 class TFileTableCleanup
       
   145 {
       
   146 public:
       
   147 	void SaveUserHeap(RHeap* aHeap)
       
   148 		{
       
   149 		iUserHeap = aHeap;
       
   150 		}
       
   151 
       
   152 	~TFileTableCleanup()
       
   153 	{
       
   154 		User::SwitchHeap(iUserHeap);
       
   155 	}
       
   156 
       
   157 private:
       
   158 	RHeap* iUserHeap;
       
   159 };
       
   160 
       
   161 
       
   162 class CFileTable
       
   163 /*
       
   164 @internalComponent
       
   165 */
       
   166 	{
       
   167 public:
       
   168 	CFileTable();
       
   169 	~CFileTable();
       
   170 
       
   171 	TInt Init(RHeap* aHeap = NULL);
       
   172 	void Close();
       
   173 	void Default(CFileDescBase* aRedirMedia, CFileDescBase* aStdErrMedia);
       
   174 	TInt Reserve();
       
   175 	TInt Attach(TInt aFid, CFileDescBase* aFile);
       
   176 	TInt Detach(TInt aFid, CFileDescBase*& aDetached);
       
   177 	TInt At(TInt aFid, CFileDescBase*& aFound) const;
       
   178 	TInt Reserve(TInt aFids[3]);
       
   179 	TInt Detach(TInt aFids[3]);
       
   180 
       
   181 	int dup (int fid, int& anErrno);
       
   182 	int dup2 (int fid1, int fid2, int& anErrno);
       
   183 	int open (const wchar_t* name, int mode, int perms, int& anErrno);
       
   184 	int close (int fid, int& anErrno);
       
   185 
       
   186 	int UserClose (int fid, int& anErrno);
       
   187 
       
   188 	off_t lseek (int fid, off_t offset, int whence, int& anErrno);
       
   189 	int fstat (int fid, struct stat* st, int& anErrno);
       
   190 	int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs);
       
   191 	int listen (int fd, int n, int& anErrno);
       
   192 	int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
       
   193 	int sockname (int fd, struct sockaddr* address, unsigned long* aAddrLen,int anEnd, int& anErrno);
       
   194 	int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
       
   195 	int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
       
   196 	int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
       
   197 	int ioctlcancel (int fid, int& anErrno);
       
   198 	int fcntl (int aFid, int aCmd, long anArg, int& anErrno);
       
   199 
       
   200 	TInt Asynch (int fid, CFileDescBase*& aFile);
       
   201 
       
   202 	int popen (const wchar_t* file, const wchar_t* cmd,const char* mode, int& anErrno);
       
   203 	int pclose (int aFid, int& anErrno);
       
   204 	int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno);
       
   205 	int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno);
       
   206 	int waitpid (int pid, int* status, int options, int& anErrno);
       
   207 
       
   208 	int posix_spawn (int* pid, const wchar_t* wpath,
       
   209 					 const posix_spawn_file_actions_t* file_actions,
       
   210 					 const posix_spawnattr_t* attrp,
       
   211 					 const wchar_t* wargs, wchar_t** wenvp);
       
   212 
       
   213 	void TransferToChild (RProcess& child, TInt aFds[], TInt aWhich, TInt aSlot);
       
   214 	void PassEnvToChild (RProcess& child, wchar_t** aEnvp);
       
   215 	void PassFileActionsToChild (RProcess& child,
       
   216 								 const posix_spawn_file_actions_t* aFileActions);
       
   217 
       
   218 #ifdef SYMBIAN_OE_POSIX_SIGNALS
       
   219 	void TransferSigMaskToChild(RProcess& childproc,TDes& sigmask);
       
   220 	void CheckOrigins (wchar_t**& wenvp, int& aCount, TUint64 & aSigMask);
       
   221 #else
       
   222 	void CheckOrigins (wchar_t**& wenvp, int& aCount);
       
   223 #endif
       
   224 	TInt InheritFiles(CFileDesTransferServer* server);
       
   225 	int pipe (int fildes[2], int& anErrno);
       
   226 	int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno, RFs& aFs);
       
   227 	int CreatePipeDesc (int fildes, RPipe& aHandle, TUint16 aMode = 0);
       
   228 	void ClosePipe (int fds[2], int& err);
       
   229 
       
   230 	static CFileDescBase* FifoOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno);
       
   231 	int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno, RFs& aFs);
       
   232 	static CFileDescBase* LinkOpen (const wchar_t* pathName, mode_t mode, int perms, int& anErrno, RFs& aFs);
       
   233 	int unlink (RFs& aFs, const wchar_t *pathName, int& anErrno);
       
   234 	int AcceptFileSocket(CFileSocketDesc* pfs, const struct sockaddr_un* addr, int& anErrno, RFs& aFs);
       
   235 	TInt RConnectionCount();
       
   236 	TInt RConnectionAt (TInt aRcIndex, RConnection *&aRc);
       
   237 	TInt AddRConnectionPtr (RConnection *aRc, TInt &aRcIndex);
       
   238 	void RemoveRConnectionPtrAt (TInt aRcIndex);
       
   239 	void DeleteRConnectionList();
       
   240 
       
   241 	CFileDesTransferServer* NewFDTransferServerL(RSemaphore &sem);
       
   242 	void StartFDTransferServer(CFileDesTransferServer* pServer);
       
   243 	void CloseFDTransferServer(CFileDesTransferServer* pServer);
       
   244 
       
   245 	int SetEcho(int aFd, TUint8 aEcho, int& aErrno);
       
   246 
       
   247 	void DoTransferAll(RSemaphore &sem,TDesC& name);
       
   248 	TInt GetFileCount() const
       
   249 		{
       
   250 		return iFids.Count();
       
   251 		}
       
   252 
       
   253 	void Lock()
       
   254 		{
       
   255 		iFidLock.Wait();
       
   256 		}
       
   257 
       
   258 	void Unlock()
       
   259 		{
       
   260 		iFidLock.Signal();
       
   261 		}
       
   262 
       
   263 private:
       
   264 	TFileTableCleanup	iCleanup;
       
   265 	CArrayPtrSeg<CFileDescBase> iFids;
       
   266 	// invoked by dup
       
   267 	TInt Dup(TInt aFid);
       
   268 	// invoked by both dup2 and fcntl with F_DUPFD
       
   269 	TInt Dup2(TInt aFid, TInt aFid2, TBool aCloseFid2);
       
   270 	// the real dup-er.
       
   271     TInt DupFd(TInt aFid1, TInt aFid2);
       
   272 	void Release(TInt aFid);
       
   273 
       
   274 	//Lock for protecting FIDs across threads
       
   275 	RFastLock iFidLock;
       
   276 
       
   277 	//stores pids of all children of this process
       
   278 	RArray<TChild> iChildren;
       
   279 
       
   280 	//Methods to manipulate iChildren
       
   281 	void AddChild(const TChild& aChild);
       
   282 	void RemoveChild(TInt aIdx);
       
   283 
       
   284 	void ExpandFTableL(TInt count);
       
   285 
       
   286 	const RArray<TChild>& GetChildren() const
       
   287 		{
       
   288 		return iChildren;
       
   289 		}
       
   290 
       
   291 	TInt FindChild(const TInt aFid) const
       
   292 		{
       
   293 		return iChildren.Find(TChild(aFid),
       
   294 							  TIdentityRelation<TChild>(TChild::MatchByFid));
       
   295 		}
       
   296 
       
   297 	TInt FindChild(const TProcessId aPid) const
       
   298 		{
       
   299 		return iChildren.Find(TChild(-1, aPid),
       
   300 							  TIdentityRelation<TChild>(TChild::MatchByPid));
       
   301 		}
       
   302 
       
   303 	CArrayPtrSeg<RConnection> iRConnectionList;
       
   304 	//Lock for protecting iRConnectionList across threads
       
   305 	RFastLock iRcLock;
       
   306 
       
   307 	// A pointer to the private heap
       
   308 	RHeap* iPrivateHeap;
       
   309 	friend class CFileDesTransferSession;
       
   310 	};
       
   311 
       
   312 
       
   313 class PosixFilesystem
       
   314 /*
       
   315 @internalComponent
       
   316 */
       
   317 	{
       
   318 public:
       
   319 	static wchar_t* getcwd(RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno);
       
   320 	static int chdir(RFs& aFs, const wchar_t* path, int& anErrno);
       
   321 	static int mkdir(RFs& aFs, const wchar_t* path, int perms, int& anErrno);
       
   322 	static int rmdir(RFs& aFs, const wchar_t* path, int& anErrno);
       
   323 	static int chmod(RFs& aFs, const wchar_t* path, int perms, int& anErrno);
       
   324 	static int reg_unlink(RFs& aFs, const wchar_t* path, int& anErrno);
       
   325 	static int stat(RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno);
       
   326 	static int rename(RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno);
       
   327 	static TInt ResolvePath(TParse& aResult, const wchar_t* path, TDes* aFilename);
       
   328 	static TInt SetDefaultDir(RFs& aFs);
       
   329 	static TInt CreateDefaultPrivatePath(RFs& aFs);
       
   330 	static int utime(RFs& aFs, const wchar_t* name, const struct utimbuf* filetimes, int& anErrno);
       
   331 	};
       
   332 
       
   333 
       
   334 class TAccessPointRecord
       
   335 	{
       
   336 public:	
       
   337 	TUint32 iId;
       
   338 	TBuf<KCommsDbSvrMaxColumnNameLength> iName;
       
   339 	TUint32 iDialogPref;
       
   340 	TUint32 iDirection;
       
   341 	TUint32 iService;
       
   342 	TBuf<KCommsDbSvrMaxColumnNameLength> iServiceType;
       
   343 	TUint32 iBearer;
       
   344 	TBuf<KCommsDbSvrMaxColumnNameLength> iBearerType;
       
   345 	TUint32 iNetwork;
       
   346 	TUint32 iNetworkWeighting;
       
   347 	TUint32 iLocation;
       
   348 public:
       
   349 	TAccessPointRecord();
       
   350 	
       
   351 	};
       
   352 
       
   353 // This structure encapsulates an aselect request
       
   354 NONSHARABLE_STRUCT ( TaselectRequestInfo )
       
   355 	{
       
   356 	TThreadId iId;
       
   357 	int iMaxFd;
       
   358 	fd_set* iReadFds;
       
   359 	fd_set* iWriteFds;
       
   360 	fd_set* iExceptFds;
       
   361 	struct timeval *itvptr;
       
   362 	TRequestStatus* iRequestStatus;
       
   363 	};
       
   364 
       
   365 // Holds the information about aselect requests, this used required
       
   366 // for cancellation of the aselect requests
       
   367 NONSHARABLE_CLASS ( TASelectRequest )
       
   368 	{
       
   369 public:
       
   370 	// Thread id of the thread processing the aselect
       
   371 	TThreadId iThreadId;
       
   372 	// Request object used for the request
       
   373 	TRequestStatus* iRequestStatus;
       
   374 	};
       
   375 
       
   376 NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase
       
   377 /*
       
   378 @internalComponent
       
   379 */
       
   380 	{
       
   381 public:
       
   382 
       
   383 
       
   384 	IMPORT_C CLocalSystemInterface();
       
   385 	IMPORT_C ~CLocalSystemInterface();
       
   386 
       
   387 #ifdef __SYMBIAN_COMPILE_UNUSED__
       
   388 	CLocalSystemInterface& Clone();
       
   389 	void Release();
       
   390 	void TerminateProcess(int status);
       
   391 #endif //__SYMBIAN_COMPILE_UNUSED__
       
   392 
       
   393 	int AddToDirList(DIR *aDir);
       
   394 	int RemoveDirFromList(DIR* aDir);
       
   395 	int FindInDirList(DIR* aDir);
       
   396 
       
   397 	void Exit(int code);
       
   398 
       
   399 	int dup (int fid, int& anErrno);
       
   400 	int dup2 (int fid, int fid2, int& anErrno);
       
   401 	int open (const wchar_t* name, int mode, int perms, int& anErrno);
       
   402 	int read (int fid, char* buf, unsigned long len, int& anErrno);
       
   403 	int write (int fid, const char* buf, unsigned long len, int& anErrno);
       
   404 	int fsync (int fid, int& anErrno);
       
   405 	int close (int fid, int& anErrno);
       
   406 	off_t lseek (int fid, off_t offset, int whence, int& anErrno);
       
   407 	int fstat (int fid, struct stat* st, int& anErrno);
       
   408 	int ioctl (int fid, int cmd, void* param, int& anErrno);
       
   409 	int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
       
   410 	int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
       
   411 
       
   412 #ifdef __SYMBIAN_COMPILE_UNUSED__
       
   413 	int ioctl_cancel (int fid, int& anErrno);
       
   414 #endif //__SYMBIAN_COMPILE_UNUSED__
       
   415 
       
   416 	wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno);
       
   417 
       
   418 	int chdir (const wchar_t* path, int& anErrno);
       
   419 	int mkdir (const wchar_t* path, int perms, int& anErrno);
       
   420 	int rmdir (const wchar_t* path, int& anErrno);
       
   421 	int chmod (const wchar_t* path, int perms, int& anErrno);
       
   422 	int stat (const wchar_t* name, struct stat* st, int& anErrno);
       
   423 	int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno);
       
   424 
       
   425 	IMPORT_C TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename);
       
   426 	int socket (int family, int style, int protocol, int& anErrno);
       
   427 	int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno);
       
   428 	int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno);
       
   429 	int shutdown (int fd, int how, int& anErrno);
       
   430 	int listen (int fd, int n, int& anErrno);
       
   431 	int accept (int fd, struct sockaddr *addr, size_t *size, int& anErrno);
       
   432 	int bind (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
       
   433 	int connect (int fd, const struct sockaddr* addr, unsigned long size, int& anErrno);
       
   434 	int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno);
       
   435 	int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
       
   436 	int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
       
   437 
       
   438 	int popen3 (const wchar_t *file, const wchar_t *cmd, wchar_t** envp, int fids[3], int& anErrno);
       
   439 	int waitpid (int pid, int* status, int options, int& anErrno);
       
   440 
       
   441 	int fcntl (int aFid, int aCmd, long anArg, int& anErrno);
       
   442 	int utime (const wchar_t* name, const struct utimbuf* filetimes, int& anErrno);
       
   443 
       
   444 	int popen (const wchar_t* file, const wchar_t* cmd, const char* mode, int& anErrno);
       
   445 	int pclose (int aFid, int& anErrno);
       
   446 	IMPORT_C void CheckOrigins (wchar_t**& wenvp, int& aCount);
       
   447 #ifdef SYMBIAN_OE_POSIX_SIGNALS
       
   448 	TInt SignalHandler();
       
   449 	IMPORT_C void InitSignalHandler();
       
   450 	void RegisterExitNotification(TProcessId aPid);
       
   451 
       
   452 	inline TUint64 GetSigMask()const
       
   453 	{
       
   454 		return iSigMask;
       
   455 	}
       
   456 
       
   457 	int kill(pid_t pid, int sig, int& anErrno);
       
   458 	int raise(int sig, int& anErrno);
       
   459 	int sigqueue(pid_t pid, int sig, const union sigval val, int& anErrno);
       
   460 
       
   461 	int sigfillset(sigset_t *set, int& anErrno);
       
   462 	int sigaddset(sigset_t *set, int signo, int& anErrno);
       
   463 	int sigdelset(sigset_t *set, int signo, int& anErrno);
       
   464 	int sigismember(const sigset_t *set, int signo, int& anErrno);
       
   465 	int sigandset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno);
       
   466 	int sigorset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno);
       
   467 	int sigisemptyset(const sigset_t * set, int& anErrno);
       
   468 	int sigemptyset(sigset_t * set, int& anErrno);
       
   469 
       
   470 	int sigprocmask(int how, const sigset_t *set, sigset_t *oset, int& anErrno);
       
   471 	int sighold(int signo, int& anErrno);
       
   472 	int sigrelse(int signo, int& anErrno);
       
   473 	int sigpause(int signo, int& anErrno);
       
   474 
       
   475 	int sigwait(const sigset_t *set, int *sig, int& anErrno);
       
   476 	int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout, int& anErrno);
       
   477 	int sigwaitinfo(const sigset_t *set, siginfo_t *info, int& anErrno);
       
   478 	int sigaction(int sig, const struct sigaction *act, struct sigaction *oact, int& anErrno);
       
   479 	TSignalHandler sigset(int aSigNum, TSignalHandler disp, int& anErrno);
       
   480 	TSignalHandler bsd_signal(int aSigNum, TSignalHandler aFunc,int& anErrno);
       
   481 	TSignalHandler signal(int aSigNum, TSignalHandler aFunc,int& anErrno);
       
   482 	int sigignore(int aSigNum, int& anErrno);
       
   483 	unsigned int alarm(unsigned int seconds);
       
   484 	int sigpending(sigset_t *set,int& anErrno);
       
   485 
       
   486 #ifdef SYMBIAN_OE_LIBRT	
       
   487 	//start timers...
       
   488 	IMPORT_C TInt AddTimer(const TInt& aTimerId);
       
   489 	IMPORT_C TInt DeleteTimer(const TInt& aTimerId);
       
   490 	IMPORT_C TInt IncrementOverrun(const TInt& aTimerId);
       
   491 	IMPORT_C TInt ResetOverrun(const TInt& aTimerId);
       
   492 	IMPORT_C TInt Overrun(const TInt& aTimerId);
       
   493 	IMPORT_C TInt RaiseTimerSignal(int sig, int timerid);
       
   494 	//end timers
       
   495 #endif //SYMBIAN_OE_LIBRT
       
   496 #endif // SYMBIAN_OE_POSIX_SIGNALS
       
   497     int pipe (int fildes[2], int& anErrno );
       
   498     int mkfifo (const wchar_t *pathname, mode_t mode, int& anErrno);
       
   499     int link (const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno );
       
   500     int unlink (const wchar_t *pathName, int& anErrno );
       
   501 
       
   502 	int select (int maxfd, fd_set* readfds,fd_set* writefds,fd_set* exceptfds, struct timeval* tvptr, int& anErrno);
       
   503 
       
   504 	int aselect(int maxfd, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *tvptr, TRequestStatus* requeststatus,int& anErrno);
       
   505 
       
   506 	int cancelaselect(TRequestStatus* requeststatus,int& anErrno,int performcleanup = 0);
       
   507 		
       
   508 	int eselect(int maxfd, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *tvptr, int arraycount,TRequestStatus* waitarray,int& anErrno);
       
   509 	
       
   510 	static TInt handleaselect(TAny* aPtr);
       
   511 	
       
   512 	RArray<TASelectRequest>& ASelectRequest();
       
   513 	
       
   514 	RFastLock& ASelectLock();
       
   515 	int system (const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno );
       
   516 	const wchar_t* GetDirName (int aFid);
       
   517 	IMPORT_C int Truncate (int aFid, off_t anOffset, int& anErrno);
       
   518 	int fchmod (int fd , mode_t  perms, int& anErrno);
       
   519 
       
   520 	int posix_spawn (int* pid, const wchar_t* wpath,
       
   521 					 const posix_spawn_file_actions_t* file_actions,
       
   522 					 const posix_spawnattr_t* attrp,
       
   523 					 const wchar_t* wargs, wchar_t** wenvp);
       
   524 
       
   525 	int SetEcho(int aFd, TUint8 aEcho, int& aErrno);
       
   526 	
       
   527 	//Set the default interface for network operations
       
   528 	int setdefaultif(const struct ifreq* aIfReq);
       
   529 	
       
   530 	IMPORT_C CFileDescBase* GetDesc(int aFid);
       
   531 
       
   532 	// functions returning session to File Server
       
   533 	IMPORT_C RFs& FileSession();
       
   534     RCommServ& CommServSession();
       
   535     RSocketServ& SockServSession();
       
   536 
       
   537 	//Dynamic Memory related APIs
       
   538 	IMPORT_C void* Alloc(size_t aNBytes);
       
   539 	IMPORT_C void* ReAlloc(void* aPtr, size_t aNBytes);
       
   540 	IMPORT_C void Free(void* aPtr);
       
   541 	IMPORT_C void* AllocTLD(TInt aSize);
       
   542 
       
   543 	//Return the private Heap memory
       
   544 	IMPORT_C RHeap* Heap();
       
   545 
       
   546 	//Return the Comms Server Lock
       
   547 	RFastLock& CommsSessionLock();
       
   548 
       
   549 	//Return reference to file table
       
   550 	const CFileTable& FileTable() const;
       
   551 	
       
   552 	//Get the default connection (RConnection) instance 
       
   553 	RConnection& GetDefaultConnection();
       
   554 	
       
   555 	//Get the saved session path of the file server session
       
   556 	TInt GetSessionPath(TDes& aPath);
       
   557 	
       
   558 	//Save the file server session path
       
   559 	TInt SaveSessionPath(const TDesC& aPath);
       
   560 	
       
   561 	static void WaitForNRequest(TRequestStatus aStatusArray[], TInt aNum);
       
   562 
       
   563 private:
       
   564 	//Helper function to read a record from the IAP table
       
   565 	void ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord);
       
   566 	//Get the connection preferences from an IAP name
       
   567 	TInt GetConnectionPreferencesL(TBuf<KCommsDbSvrMaxColumnNameLength> aIapName, 
       
   568 			 					   TCommDbConnPref &aConnPref);
       
   569 
       
   570 	// Helper function used by "select" api. 
       
   571 	// The function returns "True", if an ioctl call has been made and it is to be waited upon.
       
   572 	// The function returns "False", (if an ioctl call is not made)/(an ioctl call was made but is not to be waited upon, and will get cancelled).	
       
   573 	TBool SelectPollIssueIoctl(fd_set** aInputFds, fd_set** aOutputFds, 
       
   574 			TRequestStatus* aReqArray, TInt *aReqFds, TInt aNumReqs, TInt& nDescriptorsSet) ;
       
   575 	TInt CreateaselectThread(int maxfd, fd_set* readfds, fd_set* writefds,
       
   576 				fd_set* exceptfds, struct timeval* tvptr, 
       
   577 				TRequestStatus* requeststatus, int& anErrno);
       
   578 	
       
   579 	// Helper function for the setdefaultif() API to restart the 
       
   580 	// default RConnection with the new settings.
       
   581 	TInt StartDefConnection();
       
   582 	
       
   583 private:
       
   584 	// NOTE: iCleanup should be the first member of CLSI, since iPrivateHeap
       
   585 	// will be destroyed from within iCleanup destructor.
       
   586 	TCLSICleanup	iCleanup;
       
   587 
       
   588 	CFileTable 		iFids;
       
   589 
       
   590 	//The backend file session for the application
       
   591 	RFs 			iFs;
       
   592 	//The current session path of the application.
       
   593 	TFileName 		iSessionPath;
       
   594 	//Lock to guard the session path
       
   595 	RFastLock 		iSessionPathLock;
       
   596 	
       
   597 	RSocketServ 	iSs;
       
   598 	RCommServ 		iCs;
       
   599 
       
   600 	//Lock for protecting Socket Session across threads
       
   601 	RFastLock 		iSSLock;
       
   602 	//Lock for protecting Comms Session across threads
       
   603 	RFastLock 		iCSLock;
       
   604 	
       
   605 	//Private Heap which will be used by the library for all memory allocation
       
   606 	RHeap* 			iPrivateHeap;
       
   607 
       
   608 	//used for Opendir
       
   609 	const static TInt KDirGran = 2;
       
   610 	RPointerArray<TAny> iOpenDirList;
       
   611 
       
   612 	//in class consts
       
   613 	const static TInt KTLDInfoListGran = 4;
       
   614 	const static TInt KPtrsGran = 2;
       
   615 
       
   616 	//Thread-TLS pointers mapping
       
   617 	class TTLDInfo
       
   618 		{
       
   619 	public:
       
   620 		TTLDInfo(TThreadId id, TAny* ptr) : iTid(id), iPtrs(CLocalSystemInterface::KPtrsGran)
       
   621 			{
       
   622 			iPtrs.Append(ptr);
       
   623 			}
       
   624 		void Close(RHeap* pHeap)
       
   625 			{
       
   626 			TInt nptrs = iPtrs.Count();
       
   627 			for (TInt j = 0; j < nptrs; ++j)
       
   628 				{
       
   629 				pHeap->Free(iPtrs[j]);
       
   630 				}
       
   631 			iPtrs.Close();
       
   632 			}
       
   633 		TThreadId iTid;
       
   634 		RPointerArray<TAny> iPtrs;
       
   635 		};
       
   636 
       
   637 	//Array of Thread-TLS pointers mappings
       
   638 	RArray<TTLDInfo> iTLDInfoList;
       
   639 
       
   640 	//Protect the array from concurrent access
       
   641 	RFastLock	iTLDListLock;
       
   642 	//The default connection to be used for all network apis. 
       
   643 	RConnection iDefConnection;
       
   644 	//Protect the iDefConnection from concurrent GetDefaultConnection calls
       
   645 	RFastLock   iDefConnLock;
       
   646 	//Lock for protecting iASelectRequest across threads
       
   647 	RFastLock iASelectLock;
       
   648 		
       
   649 	// iASelectRequest holds the TASelectRequest objects of the aselect requests
       
   650 	RArray<TASelectRequest> iASelectRequest;
       
   651 	
       
   652 	// Default connection settings, set/cleared using setdefaultif
       
   653 	TConnPref* iDefConnPref;
       
   654 	
       
   655 #ifdef SYMBIAN_OE_POSIX_SIGNALS
       
   656 	// Signal handler thread
       
   657 	RThread 				iSignalHandlerThread;
       
   658 	RPipe					iSignalReadPipe;
       
   659 	RPipe					iSignalWritePipe;
       
   660 	TBool					iSignalLoopRunning;
       
   661 	RSignalSession			iSignalSession;
       
   662 	TUint64					iSigMask;
       
   663 	RArray<TSignalMessage>	iBlockedSigArray;
       
   664 	RMutex					iBlockedSAMutex;
       
   665 	TRequestStatus			iPipeReadStatus;
       
   666 
       
   667 	// For thread(s) to wait till signals initialization happens
       
   668 	TInt					iSigInitWaitCount;
       
   669 	RSemaphore				iSigInitWaitSemaphore;
       
   670 	RMutex					iSigInitWaitMutex;
       
   671 	TBool					iSignalsInitialized;
       
   672 	
       
   673 	RSemaphore				iSignalInitSemaphore;
       
   674 
       
   675 	class TChildWaiter
       
   676 		{
       
   677 	public:
       
   678 		TChildWaiter()
       
   679 			{
       
   680 			iWaiterStatus = KRequestPending;
       
   681 			iWaiterPid = 0;
       
   682 			}
       
   683 
       
   684 		virtual ~TChildWaiter() {}
       
   685 
       
   686 		TRequestStatus iWaiterStatus;
       
   687 		TProcessId iWaiterPid;
       
   688 
       
   689 		static TBool MatchByPid(const TChildWaiter& aWaiter1, const TChildWaiter& aWaiter2)
       
   690 			{
       
   691 			if((aWaiter1.iWaiterPid == aWaiter2.iWaiterPid) != 0)
       
   692 				return ETrue;
       
   693 			else
       
   694 				return EFalse;
       
   695 			}
       
   696 
       
   697 		static TBool MatchNotPending(const TChildWaiter& aWaiter1, const TChildWaiter& aWaiter2)
       
   698 			{
       
   699 			if(aWaiter1.iWaiterStatus == KRequestPending || aWaiter2.iWaiterStatus == KRequestPending)
       
   700 				return EFalse;
       
   701 			else
       
   702 				return ETrue;
       
   703 			}
       
   704 		};
       
   705 
       
   706 	class TSignalActionInfo
       
   707 		{
       
   708 	public:
       
   709 		TSignalActionInfo()
       
   710 			{
       
   711 			iSigHandler = SIG_DFL;
       
   712 			iSigAction = 0;
       
   713 			iSigFlags = 0;
       
   714 			}
       
   715 
       
   716 		virtual ~TSignalActionInfo() {}
       
   717 
       
   718 		TSignalHandler 	iSigHandler;
       
   719 		TSignalAction	iSigAction;
       
   720 		TUint32			iSigFlags;
       
   721 		};
       
   722 
       
   723 	TFixedArray<TSignalActionInfo,SIGRTMAX> iSigActions;
       
   724 	RMutex          		iSigHandlerMutex;
       
   725 	RTimer 					iAlarmTimer;
       
   726     TTime 					iAlarmStartTime;
       
   727     TRequestStatus 			iAlarmStatus;
       
   728     TBool 					iIsTimerActive;
       
   729     TUint					iCurrentTimeout;
       
   730 
       
   731     void HandleSignal(TSignalMessage& aMsg, TBool aIsDequeued = EFalse);
       
   732 	void InitializeSignalHandlers();
       
   733 	void CallDefaultHandler(int aSigNum);
       
   734 	void WaitOrHandleSignal(TSignalMessage aMsg);
       
   735 	TInt SuspendOtherThreads();
       
   736 	TInt ResumeOtherThreads();
       
   737 	TInt EnsureSignalsInitialized();
       
   738 	TInt SigWaitInternal(TUint64 aWaitSet,TSignalMessage* aMsg,TInt aTimeout,TBool aTimeCheckFailed=EFalse);
       
   739 
       
   740 	class TSignalWaiter
       
   741 		{
       
   742 	public:
       
   743 		TSignalWaiter(TUint64 aWaitMask, TSignalMessage* aMsgPtr)
       
   744 			{
       
   745 			iSigWaitSemaphore.CreateLocal(0);
       
   746 			iSigWaitMessagePtr = aMsgPtr;
       
   747 			iSigWaitMask = aWaitMask;
       
   748 
       
   749 			RThread	lThread;
       
   750 			iSigWaitThreadId = lThread.Id();
       
   751 			lThread.Close();
       
   752 			}
       
   753 
       
   754 		virtual ~TSignalWaiter()
       
   755 			{
       
   756 			iSigWaitSemaphore.Close();
       
   757 			}
       
   758 
       
   759 		TUint64				iSigWaitMask;
       
   760 		RSemaphore			iSigWaitSemaphore;
       
   761 		TSignalMessage*		iSigWaitMessagePtr;
       
   762 		TThreadId			iSigWaitThreadId;
       
   763 
       
   764 		static TBool MatchByMask(const TSignalWaiter& aWaiter1, const TSignalWaiter& aWaiter2)
       
   765 			{
       
   766 			if((aWaiter1.iSigWaitMask & aWaiter2.iSigWaitMask) != 0)
       
   767 				return ETrue;
       
   768 			else
       
   769 				return EFalse;
       
   770 			}
       
   771 
       
   772 		static TBool MatchByThreadId(const TSignalWaiter& aWaiter1, const TSignalWaiter& aWaiter2)
       
   773 			{
       
   774 			if(aWaiter1.iSigWaitThreadId == aWaiter2.iSigWaitThreadId)
       
   775 				return ETrue;
       
   776 			else
       
   777 				return EFalse;
       
   778 			}
       
   779 		};
       
   780 
       
   781 	RArray<TSignalWaiter>	iSignalWaiterArray;
       
   782 	RArray<TChildWaiter>	iChildWaiterArray;
       
   783 	RMutex					iSignalWaiterMutex;
       
   784 
       
   785 #ifdef SYMBIAN_OE_LIBRT		
       
   786 	//timers..
       
   787 	TInt FindTimer(const TInt& aTimerId);
       
   788 	class TOverrun
       
   789 		{
       
   790 		public:
       
   791 			TOverrun(const TInt& aTimerId):iTimerId(aTimerId), Overruns(0) 
       
   792 				{
       
   793 				}
       
   794 
       
   795 		TInt iTimerId;
       
   796 		TInt Overruns;
       
   797 		};
       
   798 		
       
   799 	RArray<TOverrun> 		iTimerOverruns;
       
   800 	RMutex					iTimerOverrunsMutex;
       
   801 	//timers..
       
   802 #endif // SYMBIAN_OE_LIBRT		
       
   803 	
       
   804 #endif // SYMBIAN_OE_POSIX_SIGNALS
       
   805 public:
       
   806 //ipc server session
       
   807 RIpcSession iIpcS;
       
   808 friend class RFileDesTransferSession;
       
   809 	};
       
   810 
       
   811 
       
   812 /*
       
   813 * Return global backend object to libraries
       
   814 */
       
   815 IMPORT_C CLocalSystemInterface* Backend();
       
   816 
       
   817 
       
   818 
       
   819 
       
   820 // LIBC-BACKEND specific Symbian Error Codes
       
   821 const TInt KErrMaxFdOpened = -1025;
       
   822 const TInt KErrDirectoryOpen = -1026;
       
   823 
       
   824 
       
   825 
       
   826 // Directory enumeration
       
   827 
       
   828 NONSHARABLE_STRUCT(__EPOC32_WDIR) : public CBase	// aka "class __EPOC32_WDIR with everything public"
       
   829 	{
       
   830 public:
       
   831 	__EPOC32_WDIR() {}
       
   832 	~__EPOC32_WDIR();
       
   833 
       
   834 	TInt Open();
       
   835 	TInt Open(const TDesC& aPath);
       
   836 	TInt Open(const wchar_t *_path,int*);
       
   837 	virtual TInt UpdateNarrow();
       
   838 	HBufC* iPath;
       
   839 	CDir* iEntries;
       
   840 	TInt iIndex;		// counting down, 0 means "finished"
       
   841 	struct wdirent iCurrent;
       
   842 	TInt iCount ;
       
   843 	TBuf16<KMaxFileName> iCurrentName;
       
   844 	/* *****************************************************************
       
   845 	Overloading new and delete operators so that they will
       
   846 	allocate and deallocare memory from/to the private heap of backend
       
   847 	********************************************************************/
       
   848 	inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
       
   849 		{
       
   850 		Mem::FillZ(aBase, aSize); return aBase;
       
   851 		}
       
   852 
       
   853 	inline TAny* operator new(TUint aSize) __NO_THROW
       
   854 		{
       
   855 		return Backend()->Alloc(aSize);
       
   856 		}
       
   857 
       
   858 	inline TAny* operator new(TUint aSize, TLeave)
       
   859 		{
       
   860 		TAny* ptr = Backend()->Alloc(aSize);
       
   861 		if (ptr == NULL)
       
   862 			{
       
   863 			User::Leave(KErrNoMemory);
       
   864 			}
       
   865 		return ptr;
       
   866 		}
       
   867 
       
   868 	inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
       
   869 		{
       
   870 		return Backend()->Alloc(aSize + aExtraSize);
       
   871 		}
       
   872 
       
   873 	inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
       
   874 		{
       
   875 		TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
       
   876 		if (ptr == NULL)
       
   877 			{
       
   878 			User::Leave(KErrNoMemory);
       
   879 			}
       
   880 		return ptr;
       
   881 		}
       
   882 
       
   883 	inline void operator delete(TAny *aPtr) __NO_THROW
       
   884 		{
       
   885 		Backend()->Free( aPtr );
       
   886 		}
       
   887 	};
       
   888 
       
   889 NONSHARABLE_STRUCT(__EPOC32_DIR) : public __EPOC32_WDIR
       
   890 	{
       
   891 public:
       
   892 	__EPOC32_DIR(){}
       
   893 	~__EPOC32_DIR(){}
       
   894 
       
   895 	virtual TInt UpdateNarrow();
       
   896 	struct dirent iCurrentNarrow;
       
   897 	TBuf8<KMaxFileName> iCurrentNarrowName;
       
   898 	};
       
   899 
       
   900 NONSHARABLE_STRUCT (_iconv_t)
       
   901 	{
       
   902 	TUint toCode;
       
   903 	TUint fromCode;
       
   904 	};
       
   905 
       
   906 class TUSockAddr : public TSockAddr
       
   907 /*
       
   908 Utility class for converting struct sockaddr to and from EPOC32 TSockAddr
       
   909 @internalComponent
       
   910 */
       
   911 	{
       
   912 public:
       
   913 	TUSockAddr() : TSockAddr(), iError(0) {}
       
   914 
       
   915 	TUSockAddr(TAny* addr);			// constructor form of Prepare
       
   916 	IMPORT_C TUSockAddr(const TAny* addr, TUint len);	// constructor form of Set
       
   917 private:
       
   918 	void Prepare(TAny* addr);
       
   919 	void Set(const TAny* addr, TUint len);
       
   920 public:
       
   921 	IMPORT_C void Get(TAny* addr, unsigned long* len);
       
   922 public:
       
   923 	TInt iError; // To store error status of TUSockAddr functions, refers errno.h. Notebly not Symbian error codes.
       
   924 	};
       
   925 
       
   926 
       
   927 
       
   928 
       
   929 
       
   930 #endif //SYSIF_H
       
   931