source: nanovis/branches/1.1/Trace.cpp @ 4879

Last change on this file since 4879 was 4879, checked in by ldelgass, 6 years ago

Fix for ExecuteCommand?

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[2798]1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
[3452]2/*
3 * Copyright (C) 2004-2013  HUBzero Foundation, LLC
4 *
5 * Author: George A. Howlett <gah@purdue.edu>
6 */
[848]7#include <stdio.h>
[911]8#include <stdarg.h>
[2831]9#include <syslog.h>
[3492]10#include <string.h>
[848]11
[4874]12#include <string>
13#include <sstream>
14
[1196]15#include <GL/glew.h>
[2822]16
[2831]17#include "nanovis.h"
18#include "Trace.h"
[1196]19
[4874]20using namespace nv;
21
22static std::ostringstream g_UserErrorString;
23
[3452]24#define MSG_LEN 2047
[2374]25
[4874]26/**
27 * \brief Open syslog for writing
28 */
29void
30nv::initLog()
31{
32    openlog("nanovis", LOG_CONS | LOG_PERROR | LOG_PID,  LOG_USER);
33}
34
35/**
36 * \brief Close syslog
37 */
38void
39nv::closeLog()
40{
41    closelog();
42}
43
44/**
45 * \brief Write a message to syslog
46 */
[1200]47void
[4874]48nv::LogMessage(int priority, const char *funcname,
49               const char *path, int lineNum, const char* fmt, ...)
[848]50{
[1991]51    char message[MSG_LEN+1];
52    const char *s;
53    int length;
[911]54    va_list lst;
[1984]55
[1991]56    va_start(lst, fmt);
57    s = strrchr(path, '/');
58    if (s == NULL) {
59        s = path;
60    } else {
61        s++;
[1520]62    }
[3452]63    if (priority & LOG_DEBUG) {
64        length = snprintf(message, MSG_LEN, "%s:%d(%s): ", s, lineNum, funcname);
65    } else {
66        length = snprintf(message, MSG_LEN, "%s:%d: ", s, lineNum);
67    }
[1991]68    length += vsnprintf(message + length, MSG_LEN - length, fmt, lst);
69    message[MSG_LEN] = '\0';
[3452]70
71    syslog(priority, "%s", message);
[848]72}
73
[4874]74/**
75 * \brief Write a user message to buffer
76 */
77void
78nv::logUserMessage(const char* fmt, ...)
79{
80    char message[MSG_LEN + 1];
81    int length = 0;
82    va_list lst;
83
84    va_start(lst, fmt);
85
86    length += vsnprintf(message, MSG_LEN, fmt, lst);
87    message[MSG_LEN] = '\0';
88
89    g_UserErrorString << message << "\n";
90}
91
92std::string
93nv::getUserMessages()
94{
95    return g_UserErrorString.str();
96}
97
98void
99nv::clearUserMessages()
100{
101    g_UserErrorString.str(std::string());
102}
103
[1199]104bool
[4612]105CheckFBO(GLenum *status)
[1196]106{
[4612]107    *status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
108    return (*status == GL_FRAMEBUFFER_COMPLETE_EXT);
[1199]109}
110
111void
[1200]112PrintFBOStatus(GLenum status, const char *prefix)
[1199]113{
[3559]114#ifdef WANT_TRACE
[1200]115    const char *mesg;
[3559]116
[1200]117    switch(status) {
[1196]118    case GL_FRAMEBUFFER_COMPLETE_EXT:
[1200]119        mesg = "<<<< OK >>>>";                                          break;
[1196]120    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
[1200]121        mesg = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT";              break;
[1196]122    case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
[1200]123        mesg = "GL_FRAMEBUFFER_UNSUPPORTED_EXT";                        break;
[1196]124    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
[1200]125        mesg = "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT";      break;
[1196]126    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
[1200]127        mesg = "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT";              break;
[1196]128    case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
[1200]129        mesg = "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT";                 break;
[1196]130    case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
[1200]131        mesg = "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT";             break;
[1196]132    case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
[1200]133        mesg = "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT";             break;
[1196]134    default:
[3452]135        TRACE("FB Status: %s: UNKNOWN framebuffer status %u",
[1984]136               prefix, (unsigned int)status);
[1200]137        return;
138    }
[3452]139    TRACE("FB Status: %s: %s", prefix, mesg);
[3559]140#endif  /*WANT_TRACE*/
[1196]141}
142
143bool
[1200]144CheckGL(const char *prefix)
[1196]145{
[1200]146    GLenum status = (GLenum)glGetError();
[3559]147    if (status == GL_NO_ERROR) {
148        return true;
149    }
150#ifdef WANT_TRACE
151    const char *mesg;                   
152
[1200]153    switch(status) {
[1196]154    case GL_INVALID_ENUM:
[1200]155        mesg = "GL_INVALID_ENUM";                       break;
[1196]156    case GL_INVALID_VALUE:
[1200]157        mesg = "GL_INVALID_VALUE";                      break;
[1196]158    case GL_INVALID_OPERATION:
[1200]159        mesg = "GL_INVALID_OPERATION";                  break;
[1196]160    case GL_STACK_OVERFLOW:
[1200]161        mesg = "GL_STACK_OVERFLOW";                     break;
[1196]162    case GL_STACK_UNDERFLOW:
[1200]163        mesg = "GL_STACK_UNDERFLOW";                    break;
[1196]164    case GL_OUT_OF_MEMORY:
[1200]165        mesg = "GL_OUT_OF_MEMORY";                      break;
[1196]166    case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
[1200]167        mesg = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";  break;
[1196]168    default:
[3452]169        TRACE("GL Status: %s: Unknown status %d", prefix, status);
[1200]170        return false;
171    }
[3452]172    TRACE("GL Status: %s: %s", prefix, mesg);
[3559]173#endif
[1200]174    return false;
[1196]175}
Note: See TracBrowser for help on using the repository browser.