ModuleData.h

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: ModuleData.h,v 1.10 2007/03/23 20:23:30 nuno-lopes Exp $
00020  */
00021 
00022 #ifndef __ModuleData_h__
00023 #define __ModuleData_h__
00024 
00025 #include <OPENR/OPENR.h>
00026 #include <opensdkAPI.h>
00027 #include <pthread.h>
00028 #include <semaphore.h>
00029 #include <map>
00030 #include <queue>
00031 #include <utility>
00032 #include <list>
00033 
00034 struct DesignData {
00035         void *base;
00036         size_t size;
00037 };
00038 
00039 struct message {
00040         OServiceEntry entry;
00041         void *msg;
00042         message(OServiceEntry entry_, void *msg_) : entry(entry_), msg(msg_) {}
00043 };
00044 
00045 struct perThreadStruct {
00046         //for (Find|Delete)DesignData
00047         std::map<ODesignDataID, DesignData> designDataIDs;
00048         ODesignDataID lastDesignDataID;
00049 
00050         // semaphore to signalize when there are messages to the object
00051         sem_t sem;
00052 
00053         // variables that control the shutdown proccess
00054         pthread_cond_t cond;
00055         pthread_mutex_t cond_mutex;
00056         bool exited;
00057 
00058         bool DoInitCompleted;
00059         bool DoStopCompleted;
00060 
00061         size_t OID;
00062         pthread_t threadId;
00063 
00064         std::queue<message> queue;
00065         pthread_mutex_t queue_mutex;
00066 
00067         std::list< std::pair<int,int> > ConnectHandlers;
00068 
00069         char *strtok_ptr; // for our implementation of strtok
00070 
00071         // the constructor
00072         perThreadStruct(size_t OID_)
00073         {
00074                 lastDesignDataID = 0;
00075                 OID = OID_;
00076                 exited = false;
00077                 DoInitCompleted = false;
00078                 DoStopCompleted = false;
00079 
00080                 sem_init(&sem, 0, 0);
00081                 pthread_cond_init(&cond, NULL);
00082                 pthread_mutex_init(&cond_mutex, NULL);
00083                 pthread_mutex_init(&queue_mutex, NULL);
00084         }
00085 
00086         // destructor
00087         ~perThreadStruct()
00088         {
00089                 sem_destroy(&sem);
00090                 pthread_cond_destroy(&cond);
00091                 pthread_mutex_destroy(&cond_mutex);
00092                 pthread_mutex_destroy(&queue_mutex);
00093         }
00094 };
00095 
00096 #define MOD_DATA(x) (((perThreadStruct*)pthread_getspecific(perThreadKey))->x)
00097 
00098 #endif

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