src/Emu/Utility/System/VirtualSystem.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 #ifndef __EMULATORUTILITY_VIRTUALSYSTEM_H__
00033 #define __EMULATORUTILITY_VIRTUALSYSTEM_H__
00034 
00035 #include "SysDeps/posix.h"
00036 
00037 namespace Onikiri {
00038     namespace EmulatorUtility {
00039         typedef POSIX::posix_struct_stat HostStat;
00040 
00041         // targethostFDsNX
00042         class FDConv
00043         {
00044         public:
00045             static const int InvalidFD = -1;
00046 
00047             FDConv();
00048             ~FDConv();
00049 
00050             // targetFDhostFDs
00051             int TargetToHost(int targetFD) const;
00052             int HostToTarget(int hostFD) const;
00053 
00054             // FD
00055             bool AddMap(int targetFD, int hostFD);
00056 
00057             // FD
00058             bool RemoveMap(int targetFD);
00059 
00060             //  target FD
00061             int GetFirstFreeFD();
00062         private:
00063             void ExtendFDMap();
00064             void ExtendFDMap(size_t size);
00065 
00066             // targetfdhostfd\DhostfdInvalidFD
00067             std::vector<int> m_FDTargetToHostTable;
00068         };
00069         
00070         // vZX open t@C unlink 
00071         // Unix NX
00072         //  VirtualSystem::Unlink Lq
00073         class DelayUnlinker
00074         {
00075         public:
00076             DelayUnlinker();
00077             ~DelayUnlinker();
00078 
00079             // TargetFD<>path 
00080             bool AddMap(int targetFD, std::string path);
00081             // TargetFD<>path 
00082             bool RemoveMap(int targetFD);
00083             // TargetFD<>path pX
00084             std::string GetMapPath(int targetFD);
00085             //  path 
00086             bool AddUnlinkPath(std::string path);
00087             //  path  Unlink 
00088             bool IfUnlinkable(int targetFD);
00089             //  path 
00090             bool RemoveUnlinkPath(std::string path);
00091         private:
00092             std::map<int, std::string> m_targetFDToPathTable;
00093             std::list<std::string> m_delayUnlinkPathList;
00094         };
00095 
00096         // targetzVXeit@Cj
00097         //  - targetvZXfdzXgfds
00098         //  - targetworking directory
00099         //  - 
00100         class VirtualSystem : public ParamExchange
00101         {
00102         public:
00103 
00104             VirtualSystem();
00105             ~VirtualSystem();
00106 
00107             // VirtualSystemOpent@CヲIFD\(stdin, stdout, stderr)
00108             bool AddFDMap(int targetFD, int hostFD, bool autoclose = false);
00109             // ^[QbgfBNg
00110             void SetInitialWorkingDir(const boost::filesystem::path& dir);
00111 
00112             // VXeR[Q
00113             int GetErrno();
00114 
00115             int GetPID();
00116             int GetUID();
00117             int GetEUID();
00118             int GetGID();
00119             int GetEGID();
00120 
00121             char* GetCWD(char* buf, int maxlen);
00122             int ChDir(const char* path);
00123 
00124             // t@CJDJt@CゥFD\
00125             int Open(const char* filename,int oflag);
00126 
00127             int Read(int targetFD, void *buffer, unsigned int count);
00128             int Write(int targetFD, void* buffer, unsigned int count);
00129             int Close(int targetFD);
00130 
00131             int Stat(const char* path, HostStat* s);
00132             int FStat(int fd, HostStat* s);
00133             int LStat(const char* path, HostStat* s);
00134 
00135             s64 LSeek(int fd, s64 offset, int whence);
00136             int Dup(int fd);
00137 
00138             int Access(const char* path, int mode);
00139             int Unlink(const char* path);
00140             int Rename(const char* oldpath, const char* newpath);
00141 
00142             int Truncate(const char* path, s64 length);
00143             int FTruncate(int fd, s64 length);
00144 
00145             int MkDir(const char* path, int mode);
00146 
00147             // targetFDhostFDs
00148             int FDTargetToHost(int targetFD) const
00149             {
00150                 return m_fdConv.TargetToHost(targetFD);
00151             }
00152             int FDHostToTarget(int hostFD) const
00153             {
00154                 return m_fdConv.HostToTarget(hostFD);
00155             }
00156 
00157             // 
00158             s64 GetTime();
00159             s64 GetClock();
00160             void AddInsnTick()
00161             {
00162                 m_executedInsnTick++;
00163             }
00164             s64 GetInsnTick()
00165             {
00166                 return m_executedInsnTick;
00167             }
00168 
00169             DelayUnlinker* GetDelayUnlinker(){
00170                 return &m_delayUnlinker;
00171             };
00172 
00173             BEGIN_PARAM_MAP("/Session/Emulator/System/Time/")
00174                 PARAM_ENTRY( "@UnixTime",    m_unixTime )
00175                 PARAM_ENTRY( "@EmulationMode", m_timeEmulationModeStr )
00176             END_PARAM_MAP()
00177         private:
00178             boost::filesystem::path GetHostPath(const char* targetPath);
00179             void AddAutoCloseFD(int fd);
00180             void RemoveAutoCloseFD(int fd);
00181 
00182             FDConv m_fdConv;
00183             // fXgNgゥclosefd
00184             std::vector<int> m_autoCloseFD;
00185             DelayUnlinker m_delayUnlinker;
00186 
00187             boost::filesystem::path m_cwd;
00188 
00189             // 
00190             int EmulationModeStrToInt( const std::string& );
00191             u64 m_unixTime;
00192             u64 m_executedInsnTick;
00193             std::string m_timeEmulationModeStr;
00194             int m_timeEmulationMode;
00195             enum {
00196                 TIME_HOST,
00197                 TIME_FIXED,
00198                 TIME_INSTRUCTION,
00199             };
00200         };
00201 
00202     } // namespace EmulatorUtility
00203 } // namespace Onikiri
00204 
00205 #endif

Onikiri2に対してTue Jun 18 14:34:20 2013に生成されました。  doxygen 1.4.7