root/branches/streaming-rework/src/libfreebobavc/ieee1394service.h

Revision 408, 5.3 kB (checked in by pieterpalmers, 16 years ago)

- Implemented a mechanism to allocate and deallocate iso channels in a generic manner, being by cmp or otherwise.

- cleaned all commented out code from RME, as it is getting increasingly outdated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* Ieee1394Service.cpp
2  * Copyright (C) 2005,06 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
21 #ifndef FREEBOBIEEE1394SERVICE_H
22 #define FREEBOBIEEE1394SERVICE_H
23
24 #include "fbtypes.h"
25 #include "threads.h"
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <libraw1394/raw1394.h>
30 #include <pthread.h>
31
32 #include <vector>
33
34 class Ieee1394Service{
35 public:
36     Ieee1394Service();
37     ~Ieee1394Service();
38
39     bool initialize( int port );
40
41     int getPort()
42         { return m_port; }
43    /**
44     * @brief get number of nodes on the bus
45     *
46     * Since the root node always has
47     * the highest node ID, this number can be used to determine that ID (it's
48     * LOCAL_BUS|(count-1)).
49     *
50     * @return the number of nodes on the bus to which the port is connected.
51     * This value can change with every bus reset.
52     */
53     int getNodeCount();
54    
55    /**
56     * @brief get the node id of the local node
57     *
58     * @return the node id of the local node
59     * This value can change with every bus reset.
60     */
61     nodeid_t getLocalNodeId();
62    
63    /**
64     * @brief send async read request to a node and wait for response.
65     *
66     * This does the complete transaction and will return when it's finished.
67     *
68     * @param node target node (\todo needs 0xffc0 stuff)
69     * @param addr address to read from
70     * @param length amount of data to read in quadlets
71     * @param buffer pointer to buffer where data will be saved
72    
73     * @return true on success or false on failure (sets errno)
74     */
75     bool read( fb_nodeid_t nodeId,
76                fb_nodeaddr_t addr,
77                size_t length,
78                fb_quadlet_t* buffer );
79
80     bool read_quadlet( fb_nodeid_t nodeId,
81                        fb_nodeaddr_t addr,
82                        fb_quadlet_t* buffer );
83
84     bool read_octlet( fb_nodeid_t nodeId,
85                       fb_nodeaddr_t addr,
86                       fb_octlet_t* buffer );
87
88     /**
89     * @brief send async write request to a node and wait for response.
90     *
91     * This does the complete transaction and will return when it's finished.
92     *
93     * @param node target node (\XXX needs 0xffc0 stuff)
94     * @param addr address to write to
95     * @param length amount of data to write in quadlets
96     * @param data pointer to data to be sent
97     *
98     * @return true on success or false on failure (sets errno)
99     */
100     bool write( fb_nodeid_t nodeId,
101                 fb_nodeaddr_t addr,
102                 size_t length,
103                 fb_quadlet_t* data );
104
105     bool write_quadlet( fb_nodeid_t nodeId,
106                         fb_nodeaddr_t addr,
107                         fb_quadlet_t data );
108
109     bool write_octlet(  fb_nodeid_t nodeId,
110                         fb_nodeaddr_t addr,
111                         fb_octlet_t data );
112
113     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
114                                     fb_quadlet_t* buf,
115                                     int len,
116                                     unsigned int* resp_len );
117
118     bool transactionBlockClose();
119
120     raw1394handle_t getHandle() {return m_handle;};
121
122     bool setVerbose( int verboseLevel );
123     int getVerboseLevel();
124
125     bool addBusResetHandler( Functor* functor );
126     bool remBusResetHandler( Functor* functor );
127
128 // ISO channel stuff
129 public:
130     signed int getAvailableBandwidth();
131     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
132     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
133                                      nodeid_t recv_node, int recv_plug);
134     bool freeIsoChannel(signed int channel);
135    
136 private:
137     enum EAllocType {
138         AllocFree = 0, // not allocated (by us)
139         AllocGeneric = 1, // allocated with generic functions
140         AllocCMP=2 // allocated with CMP
141     };
142
143     struct ChannelInfo {
144         int channel;
145         int bandwidth;
146         enum EAllocType alloctype;
147         nodeid_t xmit_node;
148         int xmit_plug;
149         nodeid_t recv_node;
150         int recv_plug;
151     };
152    
153     // the info for the channels we manage
154     struct ChannelInfo m_channels[64];
155    
156     bool unregisterIsoChannel(unsigned int c);
157     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
158
159 private:
160
161     bool startRHThread();
162     void stopRHThread();
163     static void* rHThread( void* arg );
164
165     void printBuffer( size_t length, fb_quadlet_t* buffer ) const;
166
167     static int resetHandlerLowLevel( raw1394handle_t handle,
168                                      unsigned int generation );
169     bool resetHandler( unsigned int generation );
170
171     raw1394handle_t m_handle;
172     raw1394handle_t m_resetHandle;
173     int             m_port;
174     unsigned int    m_generation;
175
176     pthread_t       m_thread;
177     pthread_mutex_t m_mutex;
178     bool            m_threadRunning;
179
180     typedef std::vector< Functor* > reset_handler_vec_t;
181     reset_handler_vec_t m_busResetHandlers;
182    
183     DECLARE_DEBUG_MODULE;
184 };
185
186 #endif
Note: See TracBrowser for help on using the browser.