summaryrefslogtreecommitdiffstats
path: root/mpeglib/example/yaf/yafcore/outputInterface.cpp
blob: b57563fd8a6927561dac1cba2d8a944cdcb0336f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
  This class sends an output to the outputstream
  Copyright (C) 1998  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */



#include "outputInterface.h"
#include <iostream>

using namespace std;

OutputInterface::OutputInterface(ostream* out) {
  protocolSyntax=false;
  this->out=out;
  outBuffer=new Buffer(250);
  setlinebuf(stdout);
  pthread_mutex_init(&writeOutMut,NULL);
}


OutputInterface::~OutputInterface() {
  delete outBuffer;
}

void OutputInterface::flushBuffer() {
  if (protocolSyntax) {
    (*out) << outBuffer->getData() << endl;
#ifdef _DEBUG_OUTPUT
  ofstream outfile("outstream.dbg",ios::app);
  outfile << outBuffer->getData() << endl;
  outfile.flush();
  outfile.close();
#endif
  return;
  } else {
    (*out) << "Command:" << nr << " Msg:" << outBuffer->getData() << endl;
#ifdef _DEBUG_OUTPUT
  ofstream outfile("outstream.dbg",ios::app);
  outfile <<  "Command:" << nr << " Msg:" << outBuffer->getData() << endl;
  outfile.flush();
  outfile.close();
#endif
  }
  fflush(NULL);
}



void OutputInterface::setProtocolSyntax(int proto) {
  protocolSyntax=proto;
}


void OutputInterface::setNr(int nr) {
  this->nr=nr;
}

void OutputInterface::clearBuffer() {
  outBuffer->clear();
}


void OutputInterface::appendBuffer(const char* msg) {
  outBuffer->append(msg);
}



void OutputInterface::lock() {
  pthread_mutex_lock(&writeOutMut);
}


void OutputInterface::unlock() {
  pthread_mutex_unlock(&writeOutMut);
}