Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Debugging/DebugRequest.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file DebugRequest.cpp
    00003 * Implementation of class DebugRequest
    00004 *
    00005 */
    00006
    00007 #include "Platform/SystemCall.h"
    00008 #include "DebugRequest.h"
    00009 #include <stdio.h>
    00010
    00011 DebugRequest::DebugRequest()
    00012 {
    00013   strcpy(this->description, "empty");
    00014   enable = true;
    00015 }
    00016
    00017 DebugRequest::DebugRequest(const char* description, bool enable, bool once)
    00018 {
    00019   strcpy(this->description, description);
    00020   this->enable = enable;
    00021   this->once = once;
    00022 }
    00023
    00024 DebugRequestTable::DebugRequestTable()
    00025 {
    00026   currentNumberOfDebugRequests = 0;
    00027   poll = false;
    00028   alreadyPolledDebugRequestCounter = 0;
    00029   lastName = prevLastName = 0;
    00030 }
    00031
    00032 void DebugRequestTable::addRequest(const DebugRequest& debugRequest)
    00033 {
    00034   lastName = prevLastName = 0;
    00035   if(strcmp(debugRequest.description, "poll") == 0)
    00036   {
    00037     poll = true;
    00038     pollCounter = 0;
    00039     alreadyPolledDebugRequestCounter = 0;
    00040   }
    00041   else if(strcmp(debugRequest.description, "disableAll") == 0)
    00042     removeAllRequests();
    00043   else
    00044   {
    00045     for(int i = 0; i < currentNumberOfDebugRequests; i++)
    00046     {
    00047       if(strcmp(debugRequest.description, debugRequests[i].description) == 0)
    00048       {
    00049         if(debugRequest.enable == false && debugRequest.once == false)
    00050           debugRequests[i] = debugRequests[--currentNumberOfDebugRequests];
    00051         else
    00052           debugRequests[i] = debugRequest;
    00053         return;
    00054       }
    00055     }
    00056     if(debugRequest.enable == true || debugRequest.once == true)
    00057       debugRequests[currentNumberOfDebugRequests++] = debugRequest;
    00058   }
    00059 }
    00060
    00061 void DebugRequestTable::disable(const char* name)
    00062 {
    00063   lastName = prevLastName = 0;
    00064   for(int i = 0; i < currentNumberOfDebugRequests; i++)
    00065     if(strcmp(name, debugRequests[i].description) == 0)
    00066     {
    00067       debugRequests[i] = debugRequests[--currentNumberOfDebugRequests];
    00068       return;
    00069     }
    00070 }
    00071
    00072 bool DebugRequestTable::notYetPolled(const char* name)
    00073 {
    00074   for(int i = 0; i < alreadyPolledDebugRequestCounter; ++i)
    00075     if(strcmp(name, alreadyPolledDebugRequests[i]) == 0)
    00076       return false;
    00077   alreadyPolledDebugRequests[alreadyPolledDebugRequestCounter++] = name;
    00078   return true;
    00079 }
    00080
    00081 In& operator>>(In& stream, DebugRequest& debugRequest)
    00082 {
    00083   int temp;
    00084   stream >> temp;
    00085   debugRequest.enable = temp == 1;
    00086   stream >> temp;
    00087   debugRequest.once = temp == 1;
    00088   stream >> debugRequest.description;
    00089   return stream;
    00090 }
    00091
    00092 Out& operator<<(Out& stream, const DebugRequest& debugRequest)
    00093 {
    00094   stream << debugRequest.enable;
    00095   stream << debugRequest.once;
    00096   stream << debugRequest.description;
    00097   return stream;
    00098 }