root/branches/libfreebob-2.0/src/libfreebobavc/ieee1394service.cpp

Revision 242, 2.9 kB (checked in by pieterpalmers, 18 years ago)

- made the bounce device actually work

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* tempate.cpp
2  * Copyright (C) 2005 by Daniel Wagner
3  *
4  * This file is part of FreeBob.
5  *
6  * FreeBob is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBob is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBob; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20 #include "ieee1394service.h"
21
22 #include <libavc1394/avc1394.h>
23
24 #include <errno.h>
25 #include <netinet/in.h>
26
27 #include <iostream>
28
29 using namespace std;
30
31 Ieee1394Service::Ieee1394Service()
32     : m_handle( 0 )
33     , m_port( -1 )
34 {
35 }
36
37 Ieee1394Service::~Ieee1394Service()
38 {
39     if (m_handle) {
40         raw1394_destroy_handle(m_handle);
41     }
42 }
43
44 bool
45 Ieee1394Service::initialize( int port )
46 {
47     m_handle = raw1394_new_handle_on_port( port );
48     if ( !m_handle ) {
49         if ( !errno ) {
50             cerr << "libraw1394 not compatible" << endl;
51         } else {
52             perror( "Ieee1394Service::initialize: Could not get 1394 handle" );
53             cerr << "Is ieee1394 and raw1394 driver loaded?" << endl;
54         }
55         return false;
56     }
57
58     m_port = port;
59     return true;
60 }
61
62 int
63 Ieee1394Service::getNodeCount()
64 {
65     return raw1394_get_nodecount( m_handle );
66 }
67
68 bool
69 Ieee1394Service::read( fb_nodeid_t nodeId,
70                        fb_nodeaddr_t addr,
71                        size_t size,
72                        fb_quadlet_t* buffer )
73 {
74     return raw1394_read( m_handle, nodeId, addr,  size,  buffer ) != 0;
75 }
76
77 bool
78 Ieee1394Service::write( fb_nodeid_t   nodeId,
79                         fb_nodeaddr_t addr,
80                         size_t        length,
81                         fb_quadlet_t  *data )
82 {
83     return raw1394_write( m_handle, nodeId, addr, length, data ) != 0;
84 }
85
86 fb_quadlet_t*
87 Ieee1394Service::transactionBlock( fb_nodeid_t nodeId,
88                                    fb_quadlet_t* buf,
89                                    int len,
90                                    unsigned int* resp_len )
91 {
92     for (int i = 0; i < len; ++i) {
93         buf[i] = ntohl( buf[i] );
94     }
95
96     fb_quadlet_t* result =
97         avc1394_transaction_block2( m_handle,
98                                     nodeId,
99                                     buf,
100                                     len,
101                                     resp_len,
102                                     10 );
103
104     for ( unsigned int i = 0; i < *resp_len; ++i ) {
105         result[i] = htonl( result[i] );
106     }
107
108     return result;
109 }
110
111
112 bool
113 Ieee1394Service::transactionBlockClose()
114 {
115     avc1394_transaction_block_close( m_handle );
116     return true;
117 }
Note: See TracBrowser for help on using the browser.