~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libbase/lirc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3
 
//
4
 
// This program is free software; you can redistribute it and/or modify
5
 
// it under the terms of the GNU General Public License as published by
6
 
// the Free Software Foundation; either version 3 of the License, or
7
 
// (at your option) any later version.
8
 
//
9
 
// This program is distributed in the hope that it will be useful,
10
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
// GNU General Public License for more details.
13
 
//
14
 
// You should have received a copy of the GNU General Public License
15
 
// along with this program; if not, write to the Free Software
16
 
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
//
18
 
 
19
 
#ifdef HAVE_CONFIG_H
20
 
#include "gnashconfig.h"
21
 
#endif
22
 
 
23
 
#include <string>
24
 
 
25
 
#include <iostream>
26
 
#include "gnash.h"
27
 
#include "network.h"
28
 
#include "log.h"
29
 
#include "lirc.h"
30
 
 
31
 
using namespace std;
32
 
 
33
 
namespace gnash {
34
 
 
35
 
// this number camne from the lirc irw program. If this size works for
36
 
// them, it should work for us.
37
 
const int LIRC_PACKET_SIZE = 128;
38
 
const int TIMEOUT = 10;
39
 
const int BUTTONSIZE = 10;
40
 
 
41
 
Lirc::Lirc() 
42
 
    : _sockname("/tmp/lircd"), _button(0)
43
 
{
44
 
//    GNASH_REPORT_FUNCTION;
45
 
    _button = new char[BUTTONSIZE];
46
 
}
47
 
 
48
 
Lirc::~Lirc()
49
 
{
50
 
//    GNASH_REPORT_FUNCTION;
51
 
    if (_button != 0) {
52
 
        delete _button;
53
 
    }
54
 
    closeNet();
55
 
}
56
 
 
57
 
bool
58
 
Lirc::init()
59
 
{
60
 
//    GNASH_REPORT_FUNCTION;
61
 
    return connectSocket(_sockname);
62
 
}
63
 
 
64
 
bool
65
 
Lirc::init(const char *sockpath)
66
 
{
67
 
//    GNASH_REPORT_FUNCTION;
68
 
    _connected = connectSocket(sockpath);
69
 
    return _connected;
70
 
}
71
 
 
72
 
// Whenever lircd receives a IR signal it will broadcast the
73
 
// following string to each client:
74
 
// <code> <repeat count> <button name> <remote control name>
75
 
// 0000000000000003 1 PREV LIRCEMU
76
 
// 0000000000000006 1 NEXT LIRCEMU
77
 
// 0000000000000012 1 A LIRCEMU
78
 
 
79
 
gnash::key::code
80
 
Lirc::getKey()
81
 
{
82
 
//    GNASH_REPORT_FUNCTION;
83
 
    key::code key;
84
 
    
85
 
    char buf[LIRC_PACKET_SIZE];
86
 
    memset(buf, 0, LIRC_PACKET_SIZE);
87
 
    
88
 
    // read the data if there is any
89
 
    readNet(buf, LIRC_PACKET_SIZE, TIMEOUT);
90
 
    
91
 
    string packet = buf;
92
 
    string::size_type space1 = packet.find(" ") +1;
93
 
    string::size_type space2 = packet.find(" ", space1) + 1;
94
 
    string::size_type space3 = packet.find(" ", space2) +1;
95
 
 
96
 
    string code_str = packet.substr(0, space1);
97
 
    string count_str = packet.substr(space1, space2-space1);    
98
 
    string button_str = packet.substr(space2,space3-space2);
99
 
    string control_str = packet.substr(space3);
100
 
 
101
 
    if (button_str[0] > 'A' && button_str[0] < 'Z') {
102
 
        cerr << "Character: " << button_str << endl;
103
 
        key = (gnash::key::code)button_str[0];
104
 
    }
105
 
 
106
 
    return key;
107
 
}
108
 
 
109
 
const char *
110
 
Lirc::getButton()
111
 
{
112
 
//    GNASH_REPORT_FUNCTION;
113
 
 
114
 
    char buf[LIRC_PACKET_SIZE];
115
 
    memset(buf, 0, LIRC_PACKET_SIZE);
116
 
    
117
 
    // read the data if there is any
118
 
    readNet(buf, LIRC_PACKET_SIZE, TIMEOUT);
119
 
    
120
 
    string packet = buf;
121
 
    string::size_type space1 = packet.find(" ") + 1;
122
 
    string::size_type space2 = packet.find(" ", space1) + 1;
123
 
    string::size_type space3 = packet.find(" ", space2) + 1;
124
 
    
125
 
    string button_str = packet.substr(space2, space3-space2-1);
126
 
 
127
 
    memset(_button, 0, BUTTONSIZE);
128
 
    strncpy(_button, button_str.c_str(), BUTTONSIZE);
129
 
    return _button;
130
 
}
131
 
 
132
 
} // end of gnash namespace
133
 
 
134
 
// Local Variables:
135
 
// mode: C++
136
 
// indent-tabs-mode: t
137
 
// End: