Overview   API Reference  

dataspace.hpp

00001 #if !defined(__DATASPACE_HPP__)
00002 #define __DATASPACE_HPP__
00003 
00004 //
00005 // standard includes
00006 //
00007 #include <stdint.h>
00008 #include <string>
00009 
00010 //
00011 // L4 includes
00012 //
00013 #include <l4/dm_phys/dm_phys.h>
00014 
00015 //
00016 // local includes
00017 //
00018 #include "core/util/noncopyable.hpp"
00019 #include "core/util/c++0x.hpp"
00020 
00024 struct dataspace : private noncopyable
00025 {
00027     std::string      ds_name;
00029     l4dm_dataspace_t id;
00031     l4_size_t        size;
00033     uint8_t          *base;
00034 
00035     //
00036     // constructors & destructor
00037     //
00038     inline dataspace(const std::string &name="", const l4_size_t size=0)
00039         : ds_name(name), id(L4DM_INVALID_DATASPACE), size(size), base(nullptr)
00040     {
00041         // assume the dataspace is not yet opened. store its intended name & size.
00042     }
00043 
00044     inline dataspace(const std::string &name, const l4dm_dataspace_t &id, const l4_size_t size)
00045         : ds_name(name), id(id), size(size), base(nullptr)
00046     {
00047         // assume the dataspace is opened, but not attached. initialize object and attach.
00048         attach();
00049     }
00050 
00051     inline dataspace(const std::string &name, const l4dm_dataspace_t &id,
00052                      const l4_size_t size, void *base)
00053         : ds_name(name), id(id), size(size), base(reinterpret_cast<uint8_t *>(base))
00054     {
00055         // assume the dataspace is already attached. only initialize object.
00056     }
00057 
00058     virtual inline ~dataspace(void)
00059     {
00060         detach_close();
00061     }
00062 
00063     //
00064     // set functions
00065     //
00066     inline dataspace &operator()(const std::string &name, const l4dm_dataspace_t &id,
00067                                  const l4_size_t size, void *base=nullptr)
00068     {
00069         detach_close();
00070         this->ds_name=name;
00071         this->id=id;
00072         this->size=size;
00073         this->base=reinterpret_cast<uint8_t *>(base);
00074         return *this;
00075     }
00076 
00077     //
00078     // query functions
00079     //
00080     inline const char *name(void) const
00081     {
00082         return ds_name.c_str();
00083     }
00084 
00085     inline bool is_open(void) const
00086     {
00087         return !l4dm_is_invalid_ds(id);
00088     }
00089 
00090     inline bool is_attached(void) const
00091     {
00092         return base;
00093     }
00094 
00095     inline uint8_t *data(void) const
00096     {
00097         return base;
00098     }
00099 
00100     //
00101     // L4DM: helper functions: share
00102     //
00103     virtual int share(l4_threadid_t client, uint32_t flags=L4DM_RW);
00104 
00105     //
00106     // L4RM: helper functions: attach / detach
00107     //
00108     virtual int attach(uint32_t flags=L4DM_RW);
00109     virtual int detach(void);
00110     virtual int detach_close(void);
00111 };
00112 
00113 #endif
00114 
00115 // ***** end of source ***** //
00116 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008