~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/example/yaf/yafcore/multiReader.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This class can waits for input on different istreams
 
3
  Copyright (C) 1998  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
 
 
16
#ifndef __MULTIREADER_H
 
17
#define __MULTIREADER_H
 
18
 
 
19
#include <iostream.h>
 
20
 
 
21
#include "lineStack.h"
 
22
#include "buffer.h"
 
23
 
 
24
extern "C" {
 
25
#include <sys/time.h>
 
26
#include <sys/types.h>
 
27
#include <unistd.h>
 
28
#include <errno.h>
 
29
#include <strings.h>
 
30
#include <string.h>
 
31
           }
 
32
 
 
33
/**
 
34
 The purpose of this class is to have a thread safe input method
 
35
 for yaf command.
 
36
 <p>
 
37
 Sometime the decoder thread must send data to the control thread.
 
38
 E.g. the Stream has ended. The decoder thread must inform the
 
39
 control thread that the player should go into the "off" state.
 
40
 A direct call is not thread safe and this is why the decoder
 
41
 thread must use this class. For the control thread it looks
 
42
 like the user has typed "off".
 
43
 
 
44
*/
 
45
 
 
46
#define _MAX_INPUT 5
 
47
 
 
48
typedef struct {
 
49
  LineStack* tmpLineStack;        // owned by class
 
50
  int fd;                         // filedescriptor for input              
 
51
  int empty;
 
52
} LineInput;
 
53
 
 
54
 
 
55
class MultiReader {
 
56
 
 
57
  Buffer* buffer;
 
58
  LineInput* lineInputArray[_MAX_INPUT];
 
59
  LineStack* script;
 
60
 
 
61
 public:
 
62
  MultiReader();
 
63
  ~MultiReader();
 
64
 
 
65
  int add(int fd);
 
66
  void add(LineStack* aScript);
 
67
  void add(Buffer* aScript);
 
68
  void remove (int fd);
 
69
 
 
70
  void waitForLine();
 
71
  void poll(struct timeval* timeout);
 
72
 
 
73
  int hasLine();
 
74
  void getLine(Buffer* buffer);
 
75
 
 
76
 private:
 
77
 
 
78
  void doSelect(struct timeval *timeout);
 
79
 
 
80
  int getEmptySlot();
 
81
  int getSlot(int fd);
 
82
  
 
83
 
 
84
};
 
85
 
 
86
 
 
87
 
 
88
 
 
89
 
 
90
#endif