~ubuntu-branches/ubuntu/wily/ecasound/wily-proposed

« back to all changes in this revision

Viewing changes to libecasound/eca-logger-wellformed.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-05-12 17:58:03 UTC
  • Revision ID: james.westby@ubuntu.com-20110512175803-zy3lodjecabt9r3v
Tags: upstream-2.8.0
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ------------------------------------------------------------------------
 
2
// eca-logger-wellformed.cpp: Logging implementation that outputs 
 
3
//                            messages in a well-formed format.
 
4
// Copyright (C) 2002-2004 Kai Vehmanen
 
5
//
 
6
// Attributes:
 
7
//     eca-style-version: 3
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
22
// ------------------------------------------------------------------------
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#include <iostream>
 
29
#include <string>
 
30
 
 
31
#include <kvu_numtostr.h>
 
32
 
 
33
#include "eca-logger-wellformed.h"
 
34
 
 
35
using namespace std;
 
36
 
 
37
ECA_LOGGER_WELLFORMED::ECA_LOGGER_WELLFORMED(void)
 
38
{
 
39
}
 
40
 
 
41
ECA_LOGGER_WELLFORMED::~ECA_LOGGER_WELLFORMED(void)
 
42
{
 
43
}
 
44
 
 
45
/**
 
46
 * Prints the given log message in well-formed
 
47
 * format. 
 
48
 * 
 
49
 * See section "Ecasound Interactive Mode - 
 
50
 * Well-Formed Output Mode" in the Ecasound 
 
51
 * Programmer's Guide for more detailed documentation.
 
52
 */
 
53
void ECA_LOGGER_WELLFORMED::do_msg(ECA_LOGGER::Msg_level_t level, const string& module_name, const string& log_message)
 
54
{
 
55
  if (is_log_level_set(level) == true) {
 
56
    cout << ECA_LOGGER_WELLFORMED::create_wellformed_message(level,
 
57
                                                             log_message);
 
58
  }
 
59
}
 
60
 
 
61
void ECA_LOGGER_WELLFORMED::do_flush(void) 
 
62
{
 
63
}
 
64
 
 
65
void ECA_LOGGER_WELLFORMED::do_log_level_changed(void)
 
66
{
 
67
}
 
68
 
 
69
string ECA_LOGGER_WELLFORMED::create_wellformed_message(ECA_LOGGER::Msg_level_t level, const string& message)
 
70
{
 
71
  string result, rettype;
 
72
  string::const_iterator p = message.begin();
 
73
  size_t msglen = message.size();
 
74
 
 
75
  /* 1. loglevel */
 
76
  result += kvu_numtostr(static_cast<int>(level));
 
77
    
 
78
  /* 2. space */
 
79
  result += " ";
 
80
  
 
81
  if (level == ECA_LOGGER::eiam_return_values) {
 
82
    while(p != message.end()) {
 
83
      msglen--;
 
84
      if (isspace(*p) != 0) {
 
85
        rettype = string(message.begin(), p);
 
86
        p++; /* skip space to reach start of actual msg */
 
87
        break;
 
88
      }
 
89
      ++p;
 
90
    }
 
91
  }
 
92
  
 
93
  /* 3. message size */
 
94
  result += kvu_numtostr(msglen);
 
95
  
 
96
  if (level == ECA_LOGGER::eiam_return_values) {
 
97
    /* 4. space */
 
98
    result += " ";
 
99
    
 
100
    /* 5. return type */
 
101
    result += rettype;
 
102
  }
 
103
  
 
104
  /* 6. contentblock */
 
105
  result += "\r\n";
 
106
  result += string(p,message.end()); 
 
107
  result += "\r\n\r\n";
 
108
 
 
109
  return result;
 
110
}