MCOOP.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: MCOOP.cc,v 1.8 2007/07/16 15:18:14 nuno-lopes Exp $
00020  */
00021 
00022 #define _POSIX_C_SOURCE 199309
00023 #include <cstdlib>
00024 #include <ctime>
00025 #include <sys/time.h>
00026 #include <unistd.h>
00027 #include <MCOOP.h>
00028 #include <ObjectEntryTable.h>
00029 #include <MemoryMapAgent.h>
00030 #include <ModuleData.h>
00031 
00032 extern "C" {
00033 
00034 // this function is called in stub macros and should just return
00035 void Exit(void)
00036 {
00037         // do nothing
00038 }
00039 
00040 void Prologue(InitInfo*)
00041 {
00042         // do nothing
00043 }
00044 
00045 // ---------------------------
00046 
00047 sError GetSystemTime(SystemTime* sysTime)
00048 {
00049         struct timeval tv;
00050 
00051         // TODO: check the original function semantics. is this the time past the boot, the Unix or Aibo epoch time?
00052         gettimeofday(&tv, NULL);
00053         sysTime->seconds = tv.tv_sec;
00054         sysTime->useconds = tv.tv_usec;
00055 
00056         return sSUCCESS;
00057 }
00058 
00059 
00060 sError SetTimeEvent(TimeEventInfo* info, OID dest, Selector meth, void* msg, size_t sizeOfMsg, EventID* eventID)
00061 {
00062         // TODO
00063         return sNOTIMERAVAILABLE;
00064 }
00065 
00066 sError CancelEvent(EventID eventID)
00067 {
00068         // TODO
00069         return sNOTIMERAVAILABLE;
00070 }
00071 
00072 sError NewRegion(size_t size, void** ptr)
00073 {
00074         *ptr = malloc(size);
00075         return sSUCCESS;
00076 }
00077 
00078 sError DeleteRegion(void* ptr)
00079 {
00080         free(ptr);
00081         return sSUCCESS;
00082 }
00083 
00084 sError WhoAmI(OID* oid)
00085 {
00086         oid->SetAddress((void*)MOD_DATA(OID));
00087         return sSUCCESS;
00088 }
00089 
00090 sError NewSharedMemoryRegion(size_t size, MemoryProtectionInfo info, MemoryRegionID* memRegionID, void** baseAddr)
00091 {
00092         if (info != MEMPROTINFO_R && info != MEMPROTINFO_RW) {
00093                 return sINVALIDSHAREDMEMPROTECT;
00094         }
00095 
00096         *baseAddr = malloc(size);
00097         *memRegionID = RegisterNewMemID(*baseAddr);
00098 
00099         // TODO: mark the memory segment as Read-only if asked to do so
00100 
00101         return sSUCCESS;
00102 }
00103 
00104 sError DeleteSharedMemoryRegion(MemoryRegionID memRegionID)
00105 {
00106         if (FreeMemId(memRegionID) == oSUCCESS) {
00107                 return sSUCCESS;
00108         } else {
00109                 return sINVALIDSHAREDMEMID;
00110         }
00111 }
00112 
00113 sError ChangeProtectionMemoryRegion(MemoryRegionID memRegionID, MemoryProtectionInfo info)
00114 {
00115         if (info != MEMPROTINFO_R && info != MEMPROTINFO_RW) {
00116                 return sINVALIDSHAREDMEMPROTECT;
00117         }
00118 
00119         // TODO
00120 
00121         return sSUCCESS;
00122 }
00123 
00124 sError GrowMemoryRegion(MemoryRegionID memRegionID, size_t size)
00125 {
00126         void *addr;
00127 
00128         if (GetMemID(memRegionID, &addr) != oSUCCESS) {
00129                 return sINVALIDSHAREDMEMID;
00130         }
00131 
00132         // realloc() may change the memory segment and in that case we must return an error, because
00133         // the original pointer becomes invalid
00134         if (realloc(addr, size) != addr) {
00135                 return sINVALIDSHAREDMEMID;
00136         }
00137 
00138         return sSUCCESS;
00139 }
00140 
00141 sError ShrinkMemoryRegion(MemoryRegionID memRegionID, size_t size)
00142 {
00143         return GrowMemoryRegion(memRegionID, size); // use the same implementation
00144 }
00145 
00146 sError GetPageSize(size_t *size)
00147 {
00148         *size = sysconf(_SC_PAGESIZE);
00149         return sSUCCESS;
00150 }
00151 
00152 sError Wait(longword nanosec)
00153 {
00154         struct timespec t = {0, nanosec};
00155         nanosleep(&t, NULL);
00156         return sSUCCESS;
00157 }
00158 
00159 }// end of extern "C"

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