#ifndef MMFMGR_H #define MMFMGR_H ///////////////////////////////////////////////////////////////////////// // MMFmgr.h - Provides management of shared memory for IPC // // ver 1.1 // // Language: Visual C++ 2008 // // Platform: Dell Precision T7400, Vista Ultimate, SP1 // // Application: Help for CSE687 - Object Oriented Design, Project #2 // // Author: Jim Fawcett, CST 4-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////////// /* * Module Operations: * ================== * Support asynchronous message-passing using a memory-mapped file. * This module creates and synchronizes access to memory shared between * two processes. It supplies putString() and getString() operations. * * NOTE: This module supports two way communication, but only for * one client and one server * * Required Files: * MMFmgr.h, MMFmgr.cpp, * Threads.h, Threads.cpp, locks.h * * Build Command: * cl /EHa /DTEST_MESSAGEMGR MMFmgr.cpp Threads.cpp * * Maintenance History: * ver 1.1 : 26 Mar 09 * - removed debugString references and some no longer needed includes. * - fixed a problem with project references to threads and locks modules * ver 1.0 : 22 Mar 09 * - first release */ #include #include #include class RWToggle { public: RWToggle(std::string name, int role); ~RWToggle(); void setRead(); void setWrite(); void readWait(); void writeWait(); bool isReadyForReading(); bool isReadyForWriting(); std::string name(); private: HANDLE hRead_; HANDLE hWrite_; bool readReady; std::string name_; int role_; }; inline std::string RWToggle::name() { return name_; } typedef char* Block; class MMFmgr { public: enum role { client, server }; MMFmgr(const std::string& name, size_t size, role r); ~MMFmgr(); void putBlock(Block blk); Block getBlock(); void putString(const std::string& str); std::string getString(); std::string name(); role getRole(); private: size_t size_; HANDLE hMMF_; char* pMMF_; RWToggle rwt_; std::string name_; role role_; }; inline MMFmgr::role MMFmgr::getRole() { return role_; } inline std::string MMFmgr::name() { return name_; } #endif