os/ossrv/genericopenlibs/cstdlib/INC/SYSIF.H
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32std.h>
    17 #include <e32base.h>
    18 #include <f32file.h>
    19 #include <es_sock.h>
    20 #include "ENVIRON.H"
    21 #include <stdlib.h>
    22 #include <c32comm.h>
    23 
    24 
    25 class MSystemInterface
    26 /**
    27 @internalComponent
    28 */
    29 	{
    30 public:
    31 	virtual MSystemInterface& Clone()=0;
    32 	virtual void Release()=0;
    33 	virtual void TerminateProcess(int status)=0;
    34 
    35 	virtual int dup (int fid, int& anErrno)=0;
    36 	virtual int dup2 (int fid, int fid2, int& anErrno)=0;
    37 	virtual int open (const wchar_t* name, int mode, int perms, int& anErrno)=0;
    38 	virtual int read (int fid, char* buf, unsigned long len, int& anErrno)=0;
    39 	virtual int write (int fid, const char* buf, unsigned long len, int& anErrno)=0;
    40 	virtual int fsync (int fid, int& anErrno)=0;
    41 	virtual int close (int fid, int& anErrno)=0;
    42 	virtual int lseek (int fid, int offset, int whence, int& anErrno)=0;
    43 	virtual int fstat (int fid, struct stat* st, int& anErrno)=0;
    44 	virtual int ioctl (int fid, int cmd, void* param, int& anErrno)=0;
    45 	virtual int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)=0;
    46 	virtual int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)=0;
    47 	virtual int ioctl_cancel (int fid, int& anErrno)=0;
    48 
    49 	virtual wchar_t * getcwd (wchar_t * buf, unsigned long len, int& anErrno)=0;
    50 	virtual int chdir (const wchar_t* path, int& anErrno)=0;
    51 	virtual int mkdir (const wchar_t* path, int perms, int& anErrno)=0;
    52 	virtual int rmdir (const wchar_t* path, int& anErrno)=0;
    53 	virtual int chmod (const wchar_t* path, int perms, int& anErrno)=0;
    54 	virtual int unlink (const wchar_t* path, int& anErrno)=0;
    55 	virtual int stat (const wchar_t* name, struct stat* st, int& anErrno)=0;
    56 	virtual int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno)=0;
    57 
    58 	virtual TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename)=0;
    59 
    60 	virtual int socket (int family, int style, int protocol, int& anErrno)=0;
    61 	virtual int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno)=0;
    62 	virtual int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno)=0;
    63 	virtual int shutdown (int fd, int how, int& anErrno)=0;
    64 	virtual int listen (int fd, int n, int& anErrno)=0;
    65 	virtual int accept (int fd, int& anErrno)=0;
    66 	virtual int bind (int fd, struct sockaddr* addr, unsigned long size, int& anErrno)=0;
    67 	virtual int connect (int fd, struct sockaddr* addr, unsigned long size, int& anErrno)=0;
    68 	virtual int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno)=0;
    69 	virtual int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno)=0;
    70 	virtual int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno)=0;
    71 
    72 	virtual wchar_t* getenv (const wchar_t* name)=0; 
    73 	virtual void unsetenv (const wchar_t* name)=0;
    74 	virtual int setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno)=0;
    75 
    76 	virtual int popen3 (const wchar_t *file, const wchar_t *cmd, const wchar_t *mode, wchar_t** envp, int fids[3], int& anErrno)=0;
    77 	virtual int waitpid (int pid, int* status, int options, int& anErrno)=0;
    78 	};
    79 
    80 class CFileDescBase;
    81 class CFileTable
    82 /**
    83 @internalComponent
    84 */
    85 	{
    86 public:
    87 	CFileTable();
    88 	~CFileTable();
    89 
    90 	void InitL();
    91 	void Close();
    92 	void Default(CFileDescBase* aConsole);
    93 	TInt Reserve();
    94 	TInt Attach(TInt aFid, CFileDescBase* aFile);
    95 	TInt Detach(TInt aFid, CFileDescBase*& aDetached);
    96 	TInt At(TInt aFid, CFileDescBase*& aFound) const;
    97 	TInt Reserve(TInt aFids[3]);
    98 	TInt Detach(TInt aFids[3]);
    99 
   100 	int dup (int fid, int& anErrno);
   101 	int dup2 (int fid, int fid2, int& anErrno);
   102 //	int open (const wchar_t* name, int mode, int perms, int& anErrno, RFs& aFs);
   103 	int open (const wchar_t* name, int mode, int perms, int& anErrno, RSessionBase& aFs);
   104 	int close (int fid, int& anErrno);
   105 	
   106 	int userclose (int fid, int& anErrno);
   107 
   108 	int lseek (int fid, int offset, int whence, int& anErrno);
   109 	int fstat (int fid, struct stat* st, int& anErrno);
   110 	int socket (int family, int style, int protocol, int& anErrno, RSocketServ& aSs);
   111 	int listen (int fd, int n, int& anErrno);
   112 	int bind (int fd, TSockAddr& address, int& anErrno);
   113 	int sockname (int fd, TSockAddr& address, int anEnd, int& anErrno);
   114 	int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
   115 	int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
   116 	int ioctlcomplete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
   117 	int ioctlcancel (int fid, int& anErrno);
   118 
   119 	TInt Asynch (int fid, CFileDescBase*& aFile);
   120 	
   121 private:
   122 	CArrayPtrSeg<CFileDescBase> iFids;
   123 	TInt Dup(TInt& aFid);
   124 	TInt Dup2(TInt aFid, TInt aFid2);
   125 	void Release(TInt aFid);
   126 	};
   127 
   128 class PosixFilesystem
   129 /**
   130 @internalComponent
   131 */
   132 	{
   133 public:
   134 	static wchar_t* getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno);
   135 	static int chdir (RFs& aFs, const wchar_t* path, int& anErrno);
   136 	static int mkdir (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
   137 	static int rmdir (RFs& aFs, const wchar_t* path, int& anErrno);
   138 	static int chmod (RFs& aFs, const wchar_t* path, int perms, int& anErrno);
   139 	static int unlink (RFs& aFs, const wchar_t* path, int& anErrno);
   140 	static int stat (RFs& aFs, const wchar_t* name, struct stat* st, int& anErrno);
   141 	static int rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno);
   142 	static TInt ResolvePath (RFs& aFs, TParse& aResult, const wchar_t* path, TDes* aFilename);
   143 	static TInt SetDefaultDir (RFs& aFs);
   144 	};
   145 
   146 NONSHARABLE_CLASS(CLocalSystemInterface) : public CBase, public MSystemInterface
   147 /**
   148 To make CleanupStack::PushL() and CleanupStack::Pop() work properly in the 2-phase constructor, 
   149 derivation order must be: public CBase, public MSystemInterface.
   150 
   151 @internalComponent
   152 */
   153 	{
   154 public:
   155 	static CLocalSystemInterface* NewL();	
   156 	~CLocalSystemInterface();
   157 
   158 	virtual MSystemInterface& Clone();
   159 	virtual void Release();
   160 	virtual void TerminateProcess(int status);
   161 
   162 	virtual int dup (int fid, int& anErrno);
   163 	virtual int dup2 (int fid, int fid2, int& anErrno);
   164 	virtual int open (const wchar_t* name, int mode, int perms, int& anErrno);
   165 	virtual int read (int fid, char* buf, unsigned long len, int& anErrno);
   166 	virtual int write (int fid, const char* buf, unsigned long len, int& anErrno);
   167 	virtual int fsync (int fid, int& anErrno);
   168 	virtual int close (int fid, int& anErrno);
   169 	virtual int lseek (int fid, int offset, int whence, int& anErrno);
   170 	virtual int fstat (int fid, struct stat* st, int& anErrno);
   171 	virtual int ioctl (int fid, int cmd, void* param, int& anErrno);
   172 	virtual int ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
   173 	virtual int ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno);
   174 	virtual int ioctl_cancel (int fid, int& anErrno);
   175 
   176 	virtual wchar_t* getcwd (wchar_t* buf, unsigned long len, int& anErrno);
   177 
   178 
   179 	virtual int chdir (const wchar_t* path, int& anErrno);
   180 	virtual int mkdir (const wchar_t* path, int perms, int& anErrno);
   181 	virtual int rmdir (const wchar_t* path, int& anErrno);
   182 	virtual int chmod (const wchar_t* path, int perms, int& anErrno);
   183 	virtual int unlink (const wchar_t* path, int& anErrno);
   184 	virtual int stat (const wchar_t* name, struct stat* st, int& anErrno);
   185 	virtual int rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno);
   186 
   187 	virtual TInt ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename);
   188 
   189 	virtual int socket (int family, int style, int protocol, int& anErrno);
   190 	virtual int recvfrom (int fd, char* buf, unsigned long cnt, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno);
   191 	virtual int sendto (int fd, const char* buf, unsigned long cnt, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno);
   192 	virtual int shutdown (int fd, int how, int& anErrno);
   193 	virtual int listen (int fd, int n, int& anErrno);
   194 	virtual int accept (int fd, int& anErrno);
   195 	virtual int bind (int fd, struct sockaddr* addr, unsigned long size, int& anErrno);
   196 	virtual int connect (int fd, struct sockaddr* addr, unsigned long size, int& anErrno);
   197 	virtual int sockname (int fd, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno);
   198 	virtual int getsockopt (int fd, int level, int opt, void* buf, unsigned long* len, int& anErrno);
   199 	virtual int setsockopt (int fd, int level, int opt, void* buf, unsigned long len, int& anErrno);
   200 
   201 	virtual wchar_t* getenv (const wchar_t* name); 
   202 	virtual void unsetenv (const wchar_t* name);
   203 	virtual int setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno);
   204 
   205 	virtual int popen3 (const wchar_t *file, const wchar_t *cmd, const wchar_t *mode, wchar_t** envp, int fids[3], int& anErrno);
   206 	virtual int waitpid (int pid, int* status, int options, int& anErrno);
   207 	
   208 private: 
   209 	CLocalSystemInterface();	
   210 	void ConstructL();		
   211 	
   212 private:
   213 	TInt iUseCount;
   214 	CFileTable iFids;
   215 	RFs iFs;
   216 	RSocketServ iSs;
   217 
   218 	RCommServ	iCs;
   219 	
   220 	CEnvironment iEnv;
   221 	};
   222 
   223 #include <sys/reent.h>
   224 /**
   225 @internalComponent
   226 */
   227 inline MSystemInterface& Interface(struct _reent* r)
   228 	{ return (*REINTERPRET_CAST(MSystemInterface*,r->_system)); }