RCRegion.cc

Go to the documentation of this file.
00001 /*
00002  * This file is part of openSDK.
00003  *
00004  * Copyright (C) 2006-2007 openSDK team
00005  *
00006  * openSDK is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; version 2.
00009  *
00010  * openSDK is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with openSDK; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  *     $Id: RCRegion.cc,v 1.9 2007/04/25 15:43:10 nuno-lopes Exp $
00020  */
00021 
00022 #include <OPENR/RCRegion.h>
00023 #include <stdlib.h>
00024 #include "MemoryMapAgent.h"
00025 
00026 RCRegion::RCRegion()
00027 {
00028         baseAddr_ = NULL;
00029         size_ = 0;
00030         refCounter_ = 0;
00031         memID_ = 0;
00032         offset_ = 0;
00033         status_ = UNDEF;
00034 }
00035 
00036 RCRegion::RCRegion(size_t size)
00037 {
00038         baseAddr_ = (char*)malloc(size);
00039         size_ = size;
00040         refCounter_ = 1;
00041         memID_ = RegisterNewMemID(baseAddr_);
00042         offset_ = 0;
00043         status_ = SELF_ALLOCATED;
00044 }
00045 
00046 RCRegion::RCRegion(MemoryRegionID memID, offset_t offset, void* baseAddr, size_t size)
00047 {
00048         memID_ = memID;
00049         offset_ = offset;
00050         // TODO check basAddr?
00051         baseAddr_ = (char*) baseAddr;
00052         size_ = size;
00053         refCounter_ = 1;
00054         status_ = REFERENCE_V20;
00055 }
00056 
00057 RCRegion::~RCRegion()
00058 {
00059         if (IsOwner()) {
00060                 FreeMemId(memID_);
00061         }
00062 }
00063 
00064 void RCRegion::AddReference()
00065 {
00066         ++refCounter_;
00067 }
00068 
00069 void RCRegion::RemoveReference()
00070 {
00071         if (--refCounter_ == 0) {
00072                 delete(this);
00073         }
00074 }
00075 
00076 char* RCRegion::Base() const
00077 {
00078         return baseAddr_;
00079 }
00080 
00081 size_t RCRegion::Size() const
00082 {
00083         return size_;
00084 }
00085 
00086 MemoryRegionID RCRegion::MemID() const
00087 {
00088         return memID_;
00089 }
00090 
00091 offset_t RCRegion::Offset() const
00092 {
00093         return offset_;
00094 }
00095 
00096 RCRegion::RegionType RCRegion::GetType() const
00097 {
00098         return status_;
00099 }
00100 
00101 void RCRegion::SetSize(size_t size)
00102 {
00103         size_ = size;
00104 }
00105 
00106 void* RCRegion::operator new(size_t size)
00107 {
00108         return ::new RCRegion;
00109 }
00110 
00111 void RCRegion::operator delete(void* ptr, size_t size)
00112 {
00113         ::delete (RCRegion*)ptr;
00114 }
00115 
00116 bool RCRegion::IsOwner() const
00117 {
00118         return (GetType() == SELF_ALLOCATED);
00119 }

Generated on Sun Dec 2 23:04:30 2007 for openSDK by  doxygen 1.3.9.1