Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SharedMemorySegment.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLIO/src/ICLIO/SharedMemorySegment.h                  **
00010 ** Module : ICLIO                                                  **
00011 ** Authors: Viktor Richter                                         **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/Time.h>
00035 #include <ICLUtils/Thread.h>
00036 #include <ICLUtils/Exception.h>
00037 #include <set>
00038 
00039 
00040 namespace icl {
00041   namespace io {
00042 
00044 
00058     class ICLIO_API SharedMemorySegment{
00059       public:
00060 
00062 
00068         SharedMemorySegment(std::string name="", int minsize=1);
00069 
00071         ~SharedMemorySegment();
00072 
00074 
00078         void release();
00079 
00081         std::string getName();
00082 
00084 
00088         void reset(std::string name, int minsize=0);
00089 
00091 
00094         bool isAttached();
00095 
00097 
00111         bool lock(int minsize=0);
00112 
00114 
00117         bool unlock();
00118 
00120 
00128         void forceMinSize(int minsize);
00129 
00131 
00134         int getSize();
00135 
00137 
00141         bool isEmpty() const;
00142 
00144 
00148         void* data();
00149 
00151 
00155         const void* data() const;
00156 
00158 
00162         const void* constData() const;
00163 
00165         struct Impl;
00166       private:
00168         mutable utils::Mutex m_Mutex;
00169 
00171         Impl* m_Impl;
00172 
00174         std::string m_Name;
00175 
00177         int m_Minsize;
00178     };
00179 
00181     struct ICLIO_API SharedMemorySegmentLocker{
00183         SharedMemorySegment &segment;
00184 
00186         SharedMemorySegmentLocker(SharedMemorySegment &seg, int minSize=0);
00187 
00189         SharedMemorySegmentLocker(SharedMemorySegment* seg, int minSize=0);
00190 
00192         ~SharedMemorySegmentLocker();
00193     };
00194 
00196 
00200     class ICLIO_API SharedMemorySegmentRegister
00201     {
00202       public:
00203         friend struct SharedMemorySegment::Impl;
00204 
00206         static std::set<std::string> getSegmentSet();
00207 
00209 
00213         static void freeSegment(std::string name);
00214 
00216         static void freeAllSegments();
00217 
00219 
00224         static void resetBus();
00225 
00226       private:
00228         static void addSegment(std::string name);
00229 
00231         static void removeSegment(std::string name);
00232     };
00233 
00234   } // namespace io
00235 }  // namespace icl
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines