/* Copyright (C) 2003 MySQL AB This program 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; version 2 of the License. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "SignalLoggerManager.hpp" #include #include SignalLoggerManager::SignalLoggerManager() { for (int i = 0; i < NO_OF_BLOCKS; i++){ logModes[i] = 0; } outputStream = 0; m_ownNodeId = 0; m_logDistributed = false; } SignalLoggerManager::~SignalLoggerManager() { if(outputStream != 0){ fflush(outputStream); fclose(outputStream); outputStream = 0; } } FILE * SignalLoggerManager::setOutputStream(FILE * output) { if(outputStream != 0){ fflush(outputStream); } FILE * out = outputStream; outputStream = output; return out; } FILE * SignalLoggerManager::getOutputStream() const { return outputStream; } void SignalLoggerManager::flushSignalLog() { if(outputStream != 0) fflush(outputStream); } void SignalLoggerManager::setTrace(unsigned long trace) { traceId = trace; } unsigned long SignalLoggerManager::getTrace() const { return traceId; } void SignalLoggerManager::setOwnNodeId(int nodeId){ m_ownNodeId = nodeId; } void SignalLoggerManager::setLogDistributed(bool val){ m_logDistributed = val; } int getParameter(char *blocks[NO_OF_BLOCKS], const char * par, const char * line) { const char * loc = strstr(line, par); if(loc == NULL) return 0; loc += strlen(par); int found = 0; char * copy = strdup(loc); char * tmp = copy; bool done = false; while(!done){ int len = strcspn(tmp, ", ;:\0"); if(len == 0) done = true; else { if(* (tmp + len) != ',') done = true; * (tmp + len) = 0; blocks[found] = strdup(tmp); found ++; tmp += (len + 1); } } free(copy); return found; } #define SLM_OFF 0 #define SLM_ON 1 #define SLM_TOGGLE 2 int SignalLoggerManager::log(LogMode logMode, const char * params) { char * blocks[NO_OF_BLOCKS]; const int count = getParameter(blocks, "BLOCK=", params); int cnt = 0; if((count == 1 && !strcmp(blocks[0], "ALL")) || count == 0){ for (int number = 0; number < NO_OF_BLOCKS; ++number){ cnt += log(SLM_ON, number, logMode); } } else { for (int i = 0; i < count; ++i){ BlockNumber number = getBlockNo(blocks[i]); cnt += log(SLM_ON, number, logMode); } } for(int i = 0; i= 7){ fprintf(output, " H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x\n", signalData[0], signalData[1], signalData[2], signalData[3], signalData[4], signalData[5], signalData[6]); len -= 7; signalData += 7; } if(len > 0){ for(Uint32 i = 0; i= 3) { fprintf(output, " *** invalid ***\n"); return; } const Uint32 len = ptr[i].sz; const Uint32 * data = ptr[i].p; Uint32 pos = 0; fprintf(output, " size=%u\n", (unsigned)len); while (pos < len) { printDataWord(output, pos, data[pos]); } if (len > 0) putc('\n', output); } void SignalLoggerManager::printDataWord(FILE * output, Uint32 & pos, const Uint32 data) { const char* const hex = "0123456789abcdef"; if (pos > 0 && pos % 7 == 0) putc('\n', output); putc(' ', output); putc('H', output); putc('\'', output); for (int i = 7; i >= 0; i--) putc(hex[(data >> (i << 2)) & 0xf], output); pos++; }