/* * * ProLinga-Run * * Copyright (C) 2002-2008 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Run. * * ProLinga-Run is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Run is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Run. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "RunCommon.h" #include #include #include "Thread.hpp" Thread::Thread() { strcpy(threadName, ""); strcpy(logicName, ""); threadId = 0; exitFlag = false; outputScreen = NULL; nextPtr = NULL; } Thread::~Thread() { /* Nothing */ } char *Thread::getLogicName(Thread *threadPtr, const char *name) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { return curPtr->logicName; } curPtr = curPtr->nextPtr; } /* Return */ return NULL; } void Thread::putLogicName(Thread **threadPtr, const char *name, const char *logic) { Thread *curPtr, *prevPtr, *newPtr; /* Check if thread exist in memlist */ curPtr = *threadPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { strcpy(curPtr->logicName, logic); return; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } /* Append new record */ newPtr = new Thread; strcpy(newPtr->threadName, name); strcpy(newPtr->logicName, logic); newPtr->threadId = 0; /* Next ptr null */ newPtr->nextPtr = NULL; if (prevPtr == NULL) { /* First Record */ *threadPtr = newPtr; } else { prevPtr->nextPtr = newPtr; } } pthread_t Thread::getThreadId(Thread *threadPtr, const char *name) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { return curPtr->threadId; } curPtr = curPtr->nextPtr; } /* Return */ return 0; } void Thread::putThreadId(Thread **threadPtr, const char *name, const pthread_t tid) { Thread *curPtr, *prevPtr, *newPtr; /* Check if parameter exist in memlist */ curPtr = *threadPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { curPtr->threadId = tid; return; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } /* Append new record */ newPtr = new Thread; strcpy(newPtr->threadName, name); newPtr->threadId = tid; /* Next ptr null */ newPtr->nextPtr = NULL; if (prevPtr == NULL) { /* First Record */ *threadPtr = newPtr; } else { prevPtr->nextPtr = newPtr; } } bool Thread::getExitFlag(Thread *threadPtr, const char *name) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) return curPtr->exitFlag; curPtr = curPtr->nextPtr; } /* Return */ return false; } bool Thread::getExitFlagByTid(Thread *threadPtr, const pthread_t tid) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (pthread_equal(curPtr->threadId, tid) != 0) return curPtr->exitFlag; curPtr = curPtr->nextPtr; } /* Return */ return false; } void Thread::putExitFlag(Thread **threadPtr, const char *name, bool flag) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = *threadPtr; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { curPtr->exitFlag = flag; return; } curPtr = curPtr->nextPtr; } /* Return */ return; } GtkWidget *Thread::getOutputScreen(Thread *threadPtr, const char *name) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { return curPtr->outputScreen; } curPtr = curPtr->nextPtr; } /* Return */ return NULL; } GtkWidget *Thread::getOutputScreenByTid(Thread *threadPtr, const pthread_t tid) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (pthread_equal(curPtr->threadId, tid) != 0) { return curPtr->outputScreen; } curPtr = curPtr->nextPtr; } /* Return */ return NULL; } void Thread::putOutputScreen(Thread **threadPtr, const char *name, GtkWidget *screen) { Thread *curPtr, *prevPtr, *newPtr; /* Check if thread exist in memlist */ curPtr = *threadPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(curPtr->threadName, name) == 0) { curPtr->outputScreen = screen; return; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } /* Append new record */ newPtr = new Thread; strcpy(newPtr->threadName, name); newPtr->outputScreen = screen; /* Next ptr null */ newPtr->nextPtr = NULL; if (prevPtr == NULL) { /* First Record */ *threadPtr = newPtr; } else { prevPtr->nextPtr = newPtr; } } char *Thread::getThreadNameByTid(Thread *threadPtr, const pthread_t tid) { Thread *curPtr; /* Check if parameter exist in memory */ curPtr = threadPtr; while (curPtr != NULL) { if (pthread_equal(curPtr->threadId, tid) != 0) return curPtr->threadName; curPtr = curPtr->nextPtr; } /* Return */ return false; } void Thread::deleteOne(Thread **threadPtr, const char *name) { Thread *prevPtr, *curPtr, *nextPtr; prevPtr = NULL; curPtr = *threadPtr; nextPtr = NULL; while (curPtr != NULL) { nextPtr = curPtr->nextPtr; if (strcmp(curPtr->threadName, name) == 0) { /* Unlink Thread */ if (prevPtr == NULL) *threadPtr = nextPtr; else prevPtr->nextPtr = nextPtr; /* Delete Thread */ delete curPtr; break; } prevPtr = curPtr; curPtr = nextPtr; } } void Thread::deleteList(Thread **threadPtr) { Thread *curPtr, *nextPtr; curPtr = *threadPtr; *threadPtr = NULL; while (curPtr != NULL) { nextPtr = curPtr->nextPtr; delete curPtr; curPtr = nextPtr; } } void Thread::printList(Thread *threadPtr) const { Thread *curPtr; curPtr = threadPtr; while (curPtr != NULL) { printf("Thread Name %s\n", curPtr->threadName); printf("Logic Name %s\n", curPtr->logicName); printf("Thread Id %ld\n", curPtr->threadId); if (curPtr->exitFlag == true) printf("Exit Flag TRUE \n"); else printf("Exit Flag FALSE \n"); curPtr = curPtr->nextPtr; } }