~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/sio/shl/Logtee.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
12
// - special damages arising in any way out of the use of this software.     -
13
13
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2007 amaury darsch                                   -
 
14
// - copyright (c) 1999-2011 amaury darsch                                   -
15
15
// ---------------------------------------------------------------------------
16
16
 
17
17
#include "Vector.hpp"
50
50
 
51
51
  // create a logtee with an output stream
52
52
 
53
 
  Logtee::Logtee (Output*os) {
 
53
  Logtee::Logtee (OutputStream* os) {
54
54
    Object::iref (p_tos = os);
55
55
    d_teef = DEF_TEE_MODE;
56
56
  }
57
57
 
58
58
  // create a logtee by size with an output stream
59
59
 
60
 
  Logtee::Logtee (const long size, Output*os) : Logger (size) {
 
60
  Logtee::Logtee (const long size, OutputStream* os) : Logger (size) {
61
61
    Object::iref (p_tos = os);
62
62
    d_teef = DEF_TEE_MODE;
63
63
  }
64
64
 
65
65
  // create a logtee by size, info and with an output stream
66
66
 
67
 
  Logtee::Logtee (const long size, 
68
 
                  const String& info, Output*os) : Logger (size, info) {
 
67
  Logtee::Logtee (const long size, const String& info, 
 
68
                  OutputStream* os) : Logger (size, info) {
69
69
    Object::iref (p_tos = os);
70
70
    d_teef = DEF_TEE_MODE;
71
71
  }
84
84
 
85
85
  // set the logtee output stream
86
86
 
87
 
  void Logtee::settos (Output* os) {
 
87
  void Logtee::settos (OutputStream* os) {
88
88
    wrlock ();
89
 
    Object::iref (os);
90
 
    Object::dref (p_tos);
91
 
    p_tos = os;
92
 
    unlock ();
 
89
    try {
 
90
      Object::iref (os);
 
91
      Object::dref (p_tos);
 
92
      p_tos = os;
 
93
      unlock ();
 
94
    } catch (...) {
 
95
      unlock ();
 
96
      throw;
 
97
    }
93
98
  }
94
99
 
95
100
  // return the logtee output stream
96
101
 
97
 
  Output* Logtee::gettos (void) const {
 
102
  OutputStream* Logtee::gettos (void) const {
98
103
    rdlock ();
99
 
    Output* result = p_tos;
100
 
    unlock ();
101
 
    return result;
 
104
    try {
 
105
      OutputStream* result = p_tos;
 
106
      unlock ();
 
107
      return result;
 
108
    } catch (...) {
 
109
      unlock ();
 
110
      throw;
 
111
    }
102
112
  }
103
113
 
104
114
  // set the tee flag
105
115
 
106
116
  void Logtee::setteef (const bool teef) {
107
117
    wrlock ();
108
 
    d_teef = teef;
109
 
    unlock ();
 
118
    try {
 
119
      d_teef = teef;
 
120
      unlock ();
 
121
    } catch (...) {
 
122
      unlock ();
 
123
      throw;
 
124
    }
110
125
  }
111
126
 
112
127
  // return the tee flag
113
128
 
114
129
  bool Logtee::getteef (void) const {
115
130
    rdlock ();
116
 
    bool result = d_teef;
117
 
    unlock ();
118
 
    return result;
 
131
    try {
 
132
      bool result = d_teef;
 
133
      unlock ();
 
134
      return result;
 
135
    } catch (...) {
 
136
      unlock ();
 
137
      throw;
 
138
    }
119
139
  }
120
140
 
121
141
  // add a message in the logger by log level
168
188
      // check for an integer
169
189
      Integer* iobj = dynamic_cast <Integer*> (obj);
170
190
      if (iobj != nilp) {
171
 
        long size = iobj->tointeger ();
 
191
        long size = iobj->tolong ();
172
192
        return new Logtee (size);
173
193
      }
174
194
      // check for an output stream
175
 
      Output* os = dynamic_cast <Output*> (obj);
 
195
      OutputStream* os = dynamic_cast <OutputStream*> (obj);
176
196
      if (os != nilp) {
177
197
        return new Logtee (os);
178
198
      }
181
201
    }
182
202
    // check 2 arguments
183
203
    if (argc == 2) {
184
 
      long  size = argv->getint (0);
 
204
      long  size = argv->getlong (0);
185
205
      Object* obj = argv->get (1);
186
 
      Output* os = dynamic_cast <Output*> (obj);
 
206
      OutputStream* os = dynamic_cast <OutputStream*> (obj);
187
207
      if (os == nilp) {
188
208
      throw Exception ("type-error", "invalid object with logtee",
189
209
                       Object::repr (obj));
192
212
    }
193
213
    // check 3 arguments
194
214
    if (argc == 3) {
195
 
      long   size = argv->getint    (0);
 
215
      long   size = argv->getlong (0);
196
216
      String info = argv->getstring (1);
197
217
      Object* obj = argv->get (2);
198
 
      Output* os = dynamic_cast <Output*> (obj);
 
218
      OutputStream* os = dynamic_cast <OutputStream*> (obj);
199
219
      if (os == nilp) {
200
220
      throw Exception ("type-error", "invalid object with logtee",
201
221
                       Object::repr (obj));
250
270
      }
251
271
      if (quark == QUARK_SETEES) {
252
272
        Object* obj = argv->get (0);
253
 
        Output* os = dynamic_cast <Output*> (obj);
 
273
        OutputStream* os = dynamic_cast <OutputStream*> (obj);
254
274
        if (os == nilp) {
255
275
          throw Exception ("type-error", "invalid object with set-tee-stream",
256
276
                           Object::repr (obj));