root/branches/libffado-2.0/src/libstreaming/generic/Port.cpp

Revision 1449, 4.5 kB (checked in by ppalmers, 15 years ago)

fix small bug in port enable. show port list when running verbose.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "Port.h"
25 #include "PortManager.h"
26
27 #include <stdlib.h>
28 #include <assert.h>
29
30 namespace Streaming {
31
32 IMPL_DEBUG_MODULE( Port, Port, DEBUG_LEVEL_NORMAL );
33
34 Port::Port(PortManager& m, std::string name,
35            enum E_PortType porttype, enum E_Direction direction)
36     : m_Name( name )
37     , m_disabled( true )
38     , m_buffersize( 0 )
39     , m_PortType( porttype )
40     , m_Direction( direction )
41     , m_buffer( NULL )
42     , m_manager( m )
43     , m_State( E_Created )
44 {
45     m_manager.registerPort(this);
46 }
47
48 Port::~Port() {
49     debugOutput( DEBUG_LEVEL_VERBOSE, "deleting port %s\n", getName().c_str());
50     m_manager.unregisterPort(this);
51 }
52
53 /**
54  * The idea is that you set all port parameters, and then initialize the port.
55  * This allocates all resources and makes the port usable. However, you can't
56  * change the port properties anymore after this.
57  *
58  * @return true if successfull. false if not (all resources are freed).
59  */
60 bool Port::init() {
61     debugOutput( DEBUG_LEVEL_VERBOSE, "Initialize port %s\n", m_Name.c_str());
62     if (m_State != E_Created) {
63         debugFatal("Port (%s) not in E_Created state: %d\n", m_Name.c_str(), m_State);
64         return false;
65     }
66
67     if (m_buffersize == 0) {
68         debugFatal("Cannot initialize a port with buffersize=0\n");
69         return false;
70     }
71
72     m_State = E_Initialized;
73     return true;
74 }
75
76 bool Port::reset() {
77     return true;
78 }
79
80 bool Port::setName(std::string name) {
81     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting name to %s for port %s\n",name.c_str(),m_Name.c_str());
82
83     if (m_State != E_Created) {
84         debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State);
85         return false;
86     }
87     m_Name=name;
88     return true;
89 }
90
91 bool Port::setBufferSize(unsigned int newsize) {
92     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting buffersize to %d for port %s\n",newsize,m_Name.c_str());
93     if (m_State != E_Created) {
94         debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State);
95         return false;
96     }
97     m_buffersize=newsize;
98     return true;
99 }
100
101 unsigned int Port::getEventSize() {
102     return 4; // whether it's float, int24, midi or control, it's 4
103 }
104
105 // buffer handling api's for pointer buffers
106 /**
107  * Get the buffer address
108  *
109  * @param buff
110  */
111 void *Port::getBufferAddress() {
112     return m_buffer;
113 };
114
115 /**
116  * Set the external buffer address.
117  *
118  * @param buff
119  */
120 void Port::setBufferAddress(void *buff) {
121     m_buffer=buff;
122 }
123
124 /// Enable the port. (this can be called anytime)
125 void
126 Port::enable()  {
127     debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Enabling port %s...\n",m_Name.c_str());
128     m_disabled = false;
129 }
130
131 /// Disable the port. (this can be called anytime)
132 void
133 Port::disable() {
134     debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Disabling port %s...\n",m_Name.c_str());
135     m_disabled = true;
136 }
137
138
139 /**
140  * Obtain the port type in string format
141  * @return type name of the port
142  */
143 std::string
144 Port::getPortTypeName()
145 {
146     switch(m_PortType) {
147         case E_Audio:
148             return "Audio";
149         case E_Midi:
150             return "MIDI";
151         case E_Control:
152             return "Control";
153         default:
154             return "Invalid";
155     }
156 }
157
158 void Port::show() {
159     debugOutput(DEBUG_LEVEL_VERBOSE,"Name          : %s\n", m_Name.c_str());
160     debugOutput(DEBUG_LEVEL_VERBOSE,"Enabled?      : %d\n", m_disabled);
161     debugOutput(DEBUG_LEVEL_VERBOSE,"State?        : %d\n", m_State);
162     debugOutput(DEBUG_LEVEL_VERBOSE,"Buffer Size   : %d\n", m_buffersize);
163     debugOutput(DEBUG_LEVEL_VERBOSE,"Event Size    : %d\n", getEventSize());
164     debugOutput(DEBUG_LEVEL_VERBOSE,"Port Type     : %d\n", m_PortType);
165     debugOutput(DEBUG_LEVEL_VERBOSE,"Direction     : %d\n", m_Direction);
166 }
167
168 void Port::setVerboseLevel(int l) {
169     setDebugLevel(l);
170 }
171
172 }
Note: See TracBrowser for help on using the browser.