root/branches/libffado-2.0/src/libieee1394/IsoHandlerManager.cpp

Revision 1373, 42.4 kB (checked in by ppalmers, 12 years ago)

make IsoManager? and SPM settings from config.h overridable by the user/distro config file.

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 "config.h"
25 #include "IsoHandlerManager.h"
26 #include "ieee1394service.h"
27 #include "cycletimer.h"
28 #include "libstreaming/generic/StreamProcessor.h"
29
30 #include "libutil/Atomic.h"
31 #include "libutil/PosixThread.h"
32 #include "libutil/SystemTimeSource.h"
33 #include "libutil/Watchdog.h"
34 #include "libutil/Configuration.h"
35
36 #include <cstring>
37 #include <assert.h>
38
39 IMPL_DEBUG_MODULE( IsoHandlerManager, IsoHandlerManager, DEBUG_LEVEL_NORMAL );
40 IMPL_DEBUG_MODULE( IsoTask, IsoTask, DEBUG_LEVEL_NORMAL );
41
42 using namespace Streaming;
43
44 // --- ISO Thread --- //
45
46 IsoTask::IsoTask(IsoHandlerManager& manager, enum IsoHandler::EHandlerType t)
47     : m_manager( manager )
48     , m_SyncIsoHandler ( NULL )
49     , m_handlerType( t )
50     , m_running( false )
51     , m_in_busreset( false )
52     , m_activity_wait_timeout_nsec (ISOHANDLERMANAGER_ISO_TASK_WAIT_TIMEOUT_USECS * 1000LL)
53 {
54 }
55
56 IsoTask::~IsoTask()
57 {
58     sem_destroy(&m_activity_semaphore);
59 }
60
61 bool
62 IsoTask::Init()
63 {
64     request_update = 0;
65
66     int i;
67     for (i=0; i < ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT; i++) {
68         m_IsoHandler_map_shadow[i] = NULL;
69         m_poll_fds_shadow[i].events = 0;
70     }
71     m_poll_nfds_shadow = 0;
72
73     #ifdef DEBUG
74     m_last_loop_entry = 0;
75     m_successive_short_loops = 0;
76     #endif
77
78     sem_init(&m_activity_semaphore, 0, 0);
79     m_running = true;
80     return true;
81 }
82
83 bool
84 IsoTask::requestShadowMapUpdate()
85 {
86     debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) enter\n", this);
87     INC_ATOMIC(&request_update);
88
89     // get the thread going again
90     signalActivity();
91
92     if (m_running) {
93         int timeout = 1000;
94         while(request_update && timeout--) {
95             Util::SystemTimeSource::SleepUsecRelative(1000);
96         }
97         if(timeout == 0) {
98             debugError("timeout waiting for shadow map update\n");
99         }
100     }
101     debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) exit\n", this);
102     return true;
103 }
104
105 bool
106 IsoTask::handleBusReset()
107 {
108     bool retval = true;
109     m_in_busreset = true;
110     requestShadowMapUpdate();
111     if(request_update) {
112         debugError("shadow map update request not honored\n");
113         return false;
114     }
115
116     unsigned int i, max;
117     max = m_manager.m_IsoHandlers.size();
118     for (i = 0; i < max; i++) {
119         IsoHandler *h = m_manager.m_IsoHandlers.at(i);
120         assert(h);
121
122         // skip the handlers not intended for us
123         if(h->getType() != m_handlerType) continue;
124
125         if (!h->handleBusReset()) {
126             debugWarning("Failed to handle busreset on %p\n");
127             retval = false;
128         }
129     }
130
131     // re-enable processing
132     m_in_busreset = false;
133     requestShadowMapUpdate();
134     if(request_update) {
135         debugError("shadow map update request not honored\n");
136         return false;
137     }
138     return retval;
139 }
140
141 // updates the internal stream map
142 // note that this should be executed with the guarantee that
143 // nobody will modify the parent data structures
144 void
145 IsoTask::updateShadowMapHelper()
146 {
147     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) updating shadow vars...\n", this);
148     // we are handling a busreset
149     if(m_in_busreset) {
150         m_poll_nfds_shadow = 0;
151         return;
152     }
153     unsigned int i, cnt, max;
154     max = m_manager.m_IsoHandlers.size();
155     m_SyncIsoHandler = NULL;
156     for (i = 0, cnt = 0; i < max; i++) {
157         IsoHandler *h = m_manager.m_IsoHandlers.at(i);
158         assert(h);
159
160         // skip the handlers not intended for us
161         if(h->getType() != m_handlerType) continue;
162
163         if (h->isEnabled()) {
164             m_IsoHandler_map_shadow[cnt] = h;
165             m_poll_fds_shadow[cnt].fd = h->getFileDescriptor();
166             m_poll_fds_shadow[cnt].revents = 0;
167             m_poll_fds_shadow[cnt].events = POLLIN;
168             cnt++;
169             // FIXME: need a more generic approach here
170             if(   m_SyncIsoHandler == NULL
171                && h->getType() == IsoHandler::eHT_Transmit) {
172                 m_SyncIsoHandler = h;
173             }
174
175             debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) %s handler %p added\n",
176                                               this, h->getTypeString(), h);
177         } else {
178             debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) %s handler %p skipped (disabled)\n",
179                                               this, h->getTypeString(), h);
180         }
181         if(cnt > ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT) {
182             debugWarning("Too much ISO Handlers in thread...\n");
183             break;
184         }
185     }
186
187     // FIXME: need a more generic approach here
188     // if there are no active transmit handlers,
189     // use the first receive handler
190     if(   m_SyncIsoHandler == NULL
191        && m_poll_nfds_shadow) {
192         m_SyncIsoHandler = m_IsoHandler_map_shadow[0];
193     }
194     m_poll_nfds_shadow = cnt;
195     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) updated shadow vars...\n", this);
196 }
197
198 bool
199 IsoTask::Execute()
200 {
201     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,
202                 "(%p, %s) Execute\n",
203                 this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
204     int err;
205     unsigned int i;
206     unsigned int m_poll_timeout = 10;
207
208     #ifdef DEBUG
209     uint64_t now = Util::SystemTimeSource::getCurrentTimeAsUsecs();
210     int diff = now - m_last_loop_entry;
211     if(diff < 100) {
212         debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE,
213                            "(%p, %s) short loop detected (%d usec), cnt: %d\n",
214                            this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"),
215                            diff, m_successive_short_loops);
216         m_successive_short_loops++;
217         if(m_successive_short_loops > 10000) {
218             debugError("Shutting down runaway thread\n");
219             m_running = false;
220             return false;
221         }
222     } else {
223         // reset the counter
224         m_successive_short_loops = 0;
225     }
226     m_last_loop_entry = now;
227     #endif
228
229     // if some other thread requested a shadow map update, do it
230     if(request_update) {
231         updateShadowMapHelper();
232         DEC_ATOMIC(&request_update); // ack the update
233         assert(request_update >= 0);
234     }
235
236     // bypass if no handlers are registered
237     if (m_poll_nfds_shadow == 0) {
238         debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE,
239                            "(%p, %s) bypass iterate since no handlers to poll\n",
240                            this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
241         usleep(m_poll_timeout * 1000);
242         return true;
243     }
244
245     // FIXME: what can happen is that poll() returns, but not all clients are
246     // ready. there might be some busy waiting behavior that still has to be solved.
247
248     // setup the poll here
249     // we should prevent a poll() where no events are specified, since that will only time-out
250     bool no_one_to_poll = true;
251     while(no_one_to_poll) {
252         for (i = 0; i < m_poll_nfds_shadow; i++) {
253             short events = 0;
254             IsoHandler *h = m_IsoHandler_map_shadow[i];
255             // we should only poll on a transmit handler
256             // that has a client that is ready to send
257             // something. Otherwise it will end up in
258             // busy wait looping since the packet function
259             // will defer processing (also avoids the
260             // AGAIN problem)
261             if (h->canIterateClient()) {
262                 events = POLLIN | POLLPRI;
263                 no_one_to_poll = false;
264                 // if we are going to poll() it, let's ensure
265                 // it can run until someone wants it to exit
266                 h->allowIterateLoop();
267             }
268             m_poll_fds_shadow[i].events = events;
269         }
270
271         if(no_one_to_poll) {
272             debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,
273                         "(%p, %s) No one to poll, waiting for something to happen\n",
274                         this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
275             // wait for something to happen
276             switch(waitForActivity()) {
277                 case IsoTask::eAR_Error:
278                     debugError("Error while waiting for activity\n");
279                     return false;
280                 case IsoTask::eAR_Interrupted:
281                     // FIXME: what to do here?
282                     debugWarning("Interrupted while waiting for activity\n");
283                     break;
284                 case IsoTask::eAR_Timeout:
285                     // FIXME: what to do here?
286                     debugWarning("Timeout while waiting for activity\n");
287                     no_one_to_poll = false; // exit the loop to be able to detect failing handlers
288                     break;
289                 case IsoTask::eAR_Activity:
290                     // do nothing
291                     debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
292                                        "(%p, %s) something happened\n",
293                                        this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
294                     break;
295             }
296         }
297     }
298
299     // Use a shadow map of the fd's such that we don't have to update
300     // the fd map everytime we run poll().
301     err = poll (m_poll_fds_shadow, m_poll_nfds_shadow, m_poll_timeout);
302     uint32_t ctr_at_poll_return = m_manager.get1394Service().getCycleTimer();
303
304     if (err < 0) {
305         if (errno == EINTR) {
306             debugOutput(DEBUG_LEVEL_VERBOSE, "Ignoring poll return due to signal\n");
307             return true;
308         }
309         debugFatal("poll error: %s\n", strerror (errno));
310         m_running = false;
311         return false;
312     }
313
314     // find handlers that have died
315     uint64_t ctr_at_poll_return_ticks = CYCLE_TIMER_TO_TICKS(ctr_at_poll_return);
316     bool handler_died = false;
317     for (i = 0; i < m_poll_nfds_shadow; i++) {
318         // figure out if a handler has died
319
320         // this is the time of the last packet we saw in the iterate() handler
321         uint32_t last_packet_seen = m_IsoHandler_map_shadow[i]->getLastPacketTime();
322         if (last_packet_seen == 0xFFFFFFFF) {
323             // this was not iterated yet, so can't be dead
324             debugOutput(DEBUG_LEVEL_VERY_VERBOSE,
325                         "(%p, %s) handler %d didn't see any packets yet\n",
326                         this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"), i);
327             continue;
328         }
329
330         uint64_t last_packet_seen_ticks = CYCLE_TIMER_TO_TICKS(last_packet_seen);
331         // we use a relatively large value to distinguish between "death" and xrun
332         int64_t max_diff_ticks = TICKS_PER_SECOND * 2;
333         int64_t measured_diff_ticks = diffTicks(ctr_at_poll_return_ticks, last_packet_seen_ticks);
334
335         debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
336                            "(%p, %s) check handler %d: diff = %lld, max = %lld, now: %08lX, last: %08lX\n",
337                            this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"),
338                            i, measured_diff_ticks, max_diff_ticks, ctr_at_poll_return, last_packet_seen);
339         if(measured_diff_ticks > max_diff_ticks) {
340             debugFatal("(%p, %s) Handler died: now: %08lX, last: %08lX, diff: %lld (max: %lld)\n",
341                        this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"),
342                        ctr_at_poll_return, last_packet_seen, measured_diff_ticks, max_diff_ticks);
343             m_IsoHandler_map_shadow[i]->notifyOfDeath();
344             handler_died = true;
345         }
346     }
347     if(handler_died) {
348         m_running = false;
349         return false; // one or more handlers have died
350     }
351
352     // iterate the handlers
353     for (i = 0; i < m_poll_nfds_shadow; i++) {
354         #ifdef DEBUG
355         if(m_poll_fds_shadow[i].revents) {
356             debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
357                         "(%p, %s) received events: %08X for (%d/%d, %p, %s)\n",
358                         this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"),
359                         m_poll_fds_shadow[i].revents,
360                         i, m_poll_nfds_shadow,
361                         m_IsoHandler_map_shadow[i],
362                         m_IsoHandler_map_shadow[i]->getTypeString());
363         }
364         #endif
365
366         // if we get here, it means two things:
367         // 1) the kernel can accept or provide packets (poll returned POLLIN)
368         // 2) the client can provide or accept packets (since we enabled polling)
369         if(m_poll_fds_shadow[i].revents & (POLLIN)) {
370             m_IsoHandler_map_shadow[i]->iterate(ctr_at_poll_return);
371         } else {
372             // there might be some error condition
373             if (m_poll_fds_shadow[i].revents & POLLERR) {
374                 debugWarning("(%p) error on fd for %d\n", this, i);
375             }
376             if (m_poll_fds_shadow[i].revents & POLLHUP) {
377                 debugWarning("(%p) hangup on fd for %d\n", this, i);
378             }
379         }
380     }
381     return true;
382 }
383
384 enum IsoTask::eActivityResult
385 IsoTask::waitForActivity()
386 {
387     debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
388                        "(%p, %s) waiting for activity\n",
389                        this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
390     struct timespec ts;
391     int result;
392
393     if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
394         debugError("clock_gettime failed\n");
395         return eAR_Error;
396     }
397
398     ts.tv_nsec += m_activity_wait_timeout_nsec;
399     while(ts.tv_nsec >= 1000000000LL) {
400         ts.tv_sec += 1;
401         ts.tv_nsec -= 1000000000LL;
402     }
403
404     result = sem_timedwait(&m_activity_semaphore, &ts);
405
406     if(result != 0) {
407         if (errno == ETIMEDOUT) {
408             debugOutput(DEBUG_LEVEL_VERBOSE,
409                         "(%p) sem_timedwait() timed out (result=%d)\n",
410                         this, result);
411             return eAR_Timeout;
412         } else if (errno == EINTR) {
413             debugOutput(DEBUG_LEVEL_VERBOSE,
414                         "(%p) sem_timedwait() interrupted by signal (result=%d)\n",
415                         this, result);
416             return eAR_Interrupted;
417         } else if (errno == EINVAL) {
418             debugError("(%p) sem_timedwait error (result=%d errno=EINVAL)\n",
419                         this, result);
420             debugError("(%p) timeout_nsec=%lld ts.sec=%d ts.nsec=%lld\n",
421                        this, m_activity_wait_timeout_nsec, ts.tv_sec, ts.tv_nsec);
422             return eAR_Error;
423         } else {
424             debugError("(%p) sem_timedwait error (result=%d errno=%d)\n",
425                         this, result, errno);
426             debugError("(%p) timeout_nsec=%lld ts.sec=%d ts.nsec=%lld\n",
427                        this, m_activity_wait_timeout_nsec, ts.tv_sec, ts.tv_nsec);
428             return eAR_Error;
429         }
430     }
431
432     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,
433                 "(%p, %s) got activity\n",
434                 this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
435     return eAR_Activity;
436 }
437
438 void
439 IsoTask::signalActivity()
440 {
441     // signal the activity cond var
442     sem_post(&m_activity_semaphore);
443     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,
444                 "(%p, %s) activity\n",
445                 this, (m_handlerType == IsoHandler::eHT_Transmit? "Transmit": "Receive"));
446 }
447
448 void IsoTask::setVerboseLevel(int i) {
449     setDebugLevel(i);
450     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", i );
451 }
452
453 // -- the ISO handler manager -- //
454 IsoHandlerManager::IsoHandlerManager(Ieee1394Service& service)
455    : m_State(E_Created)
456    , m_service( service )
457    , m_realtime(false), m_priority(0)
458    , m_IsoThreadTransmit ( NULL )
459    , m_IsoTaskTransmit ( NULL )
460    , m_IsoThreadReceive ( NULL )
461    , m_IsoTaskReceive ( NULL )
462 {
463 }
464
465 IsoHandlerManager::IsoHandlerManager(Ieee1394Service& service, bool run_rt, int rt_prio)
466    : m_State(E_Created)
467    , m_service( service )
468    , m_realtime(run_rt), m_priority(rt_prio)
469    , m_IsoThreadTransmit ( NULL )
470    , m_IsoTaskTransmit ( NULL )
471    , m_IsoThreadReceive ( NULL )
472    , m_IsoTaskReceive ( NULL )
473 {
474 }
475
476 IsoHandlerManager::~IsoHandlerManager()
477 {
478     stopHandlers();
479     pruneHandlers();
480     if(m_IsoHandlers.size() > 0) {
481         debugError("Still some handlers in use\n");
482     }
483     if (m_IsoThreadTransmit) {
484         m_IsoThreadTransmit->Stop();
485         delete m_IsoThreadTransmit;
486     }
487     if (m_IsoThreadReceive) {
488         m_IsoThreadReceive->Stop();
489         delete m_IsoThreadReceive;
490     }
491     if (m_IsoTaskTransmit) {
492         delete m_IsoTaskTransmit;
493     }
494     if (m_IsoTaskReceive) {
495         delete m_IsoTaskReceive;
496     }
497 }
498
499 bool
500 IsoHandlerManager::handleBusReset()
501 {
502     debugOutput( DEBUG_LEVEL_NORMAL, "bus reset...\n");
503     // A few things can happen on bus reset:
504     // 1) no devices added/removed => streams are still valid, but might have to be restarted
505     // 2) a device was removed => some streams become invalid
506     // 3) a device was added => same as 1, new device is ignored
507     if (!m_IsoTaskTransmit) {
508         debugError("No xmit task\n");
509         return false;
510     }
511     if (!m_IsoTaskReceive) {
512         debugError("No receive task\n");
513         return false;
514     }
515     if (!m_IsoTaskTransmit->handleBusReset()) {
516         debugWarning("could no handle busreset on xmit\n");
517     }
518     if (!m_IsoTaskReceive->handleBusReset()) {
519         debugWarning("could no handle busreset on recv\n");
520     }
521     return true;
522 }
523
524 void
525 IsoHandlerManager::requestShadowMapUpdate()
526 {
527     if(m_IsoTaskTransmit) m_IsoTaskTransmit->requestShadowMapUpdate();
528     if(m_IsoTaskReceive) m_IsoTaskReceive->requestShadowMapUpdate();
529 }
530
531 bool
532 IsoHandlerManager::setThreadParameters(bool rt, int priority) {
533     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) switch to: (rt=%d, prio=%d)...\n", this, rt, priority);
534     if (priority > THREAD_MAX_RTPRIO) priority = THREAD_MAX_RTPRIO; // cap the priority
535     m_realtime = rt;
536     m_priority = priority;
537
538     // grab the options from the parent
539     Util::Configuration *config = m_service.getConfiguration();
540     int ihm_iso_prio_increase = ISOHANDLERMANAGER_ISO_PRIO_INCREASE;
541     int ihm_iso_prio_increase_xmit = ISOHANDLERMANAGER_ISO_PRIO_INCREASE_XMIT;
542     int ihm_iso_prio_increase_recv = ISOHANDLERMANAGER_ISO_PRIO_INCREASE_RECV;
543     if(config) {
544         config->getValueForSetting("ieee1394.isomanager.prio_increase", ihm_iso_prio_increase);
545         config->getValueForSetting("ieee1394.isomanager.prio_increase_xmit", ihm_iso_prio_increase_xmit);
546         config->getValueForSetting("ieee1394.isomanager.prio_increase_recv", ihm_iso_prio_increase_recv);
547     }
548
549     if (m_IsoThreadTransmit) {
550         if (m_realtime) {
551             m_IsoThreadTransmit->AcquireRealTime(m_priority
552                                                  + ihm_iso_prio_increase
553                                                  + ihm_iso_prio_increase_xmit);
554         } else {
555             m_IsoThreadTransmit->DropRealTime();
556         }
557     }
558     if (m_IsoThreadReceive) {
559         if (m_realtime) {
560             m_IsoThreadReceive->AcquireRealTime(m_priority
561                                                 + ihm_iso_prio_increase
562                                                 + ihm_iso_prio_increase_recv);
563         } else {
564             m_IsoThreadReceive->DropRealTime();
565         }
566     }
567
568     return true;
569 }
570
571 bool IsoHandlerManager::init()
572 {
573     debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing ISO manager %p...\n", this);
574     // check state
575     if(m_State != E_Created) {
576         debugError("Manager already initialized...\n");
577         return false;
578     }
579
580     // grab the options from the parent
581     Util::Configuration *config = m_service.getConfiguration();
582     int ihm_iso_prio_increase = ISOHANDLERMANAGER_ISO_PRIO_INCREASE;
583     int ihm_iso_prio_increase_xmit = ISOHANDLERMANAGER_ISO_PRIO_INCREASE_XMIT;
584     int ihm_iso_prio_increase_recv = ISOHANDLERMANAGER_ISO_PRIO_INCREASE_RECV;
585     int64_t isotask_activity_timeout_usecs = ISOHANDLERMANAGER_ISO_TASK_WAIT_TIMEOUT_USECS;
586     if(config) {
587         config->getValueForSetting("ieee1394.isomanager.prio_increase", ihm_iso_prio_increase);
588         config->getValueForSetting("ieee1394.isomanager.prio_increase_xmit", ihm_iso_prio_increase_xmit);
589         config->getValueForSetting("ieee1394.isomanager.prio_increase_recv", ihm_iso_prio_increase_recv);
590         config->getValueForSetting("ieee1394.isomanager.isotask_activity_timeout_usecs", isotask_activity_timeout_usecs);
591     }
592
593     // create threads to iterate our ISO handlers
594     debugOutput( DEBUG_LEVEL_VERBOSE, "Create iso thread for %p transmit...\n", this);
595     m_IsoTaskTransmit = new IsoTask( *this, IsoHandler::eHT_Transmit );
596     if(!m_IsoTaskTransmit) {
597         debugFatal("No task\n");
598         return false;
599     }
600     m_IsoTaskTransmit->setVerboseLevel(getDebugLevel());
601     m_IsoTaskTransmit->m_activity_wait_timeout_nsec = isotask_activity_timeout_usecs * 1000LL;
602     m_IsoThreadTransmit = new Util::PosixThread(m_IsoTaskTransmit, "ISOXMT", m_realtime,
603                                                 m_priority + ihm_iso_prio_increase
604                                                 + ihm_iso_prio_increase_xmit,
605                                                 PTHREAD_CANCEL_DEFERRED);
606
607     if(!m_IsoThreadTransmit) {
608         debugFatal("No thread\n");
609         return false;
610     }
611     m_IsoThreadTransmit->setVerboseLevel(getDebugLevel());
612
613     debugOutput( DEBUG_LEVEL_VERBOSE, "Create iso thread for %p receive...\n", this);
614     m_IsoTaskReceive = new IsoTask( *this, IsoHandler::eHT_Receive );
615     if(!m_IsoTaskReceive) {
616         debugFatal("No task\n");
617         return false;
618     }
619     m_IsoTaskReceive->setVerboseLevel(getDebugLevel());
620     m_IsoThreadReceive = new Util::PosixThread(m_IsoTaskReceive, "ISORCV", m_realtime,
621                                                m_priority + ihm_iso_prio_increase
622                                                + ihm_iso_prio_increase_recv,
623                                                PTHREAD_CANCEL_DEFERRED);
624
625     if(!m_IsoThreadReceive) {
626         debugFatal("No thread\n");
627         return false;
628     }
629     m_IsoThreadReceive->setVerboseLevel(getDebugLevel());
630     // register the thread with the RT watchdog
631     Util::Watchdog *watchdog = m_service.getWatchdog();
632     if(watchdog) {
633         if(!watchdog->registerThread(m_IsoThreadTransmit)) {
634             debugWarning("could not register iso transmit thread with watchdog\n");
635         }
636         if(!watchdog->registerThread(m_IsoThreadReceive)) {
637             debugWarning("could not register iso receive thread with watchdog\n");
638         }
639     } else {
640         debugWarning("could not find valid watchdog\n");
641     }
642
643     if (m_IsoThreadTransmit->Start() != 0) {
644         debugFatal("Could not start ISO Transmit thread\n");
645         return false;
646     }
647     if (m_IsoThreadReceive->Start() != 0) {
648         debugFatal("Could not start ISO Receive thread\n");
649         return false;
650     }
651
652     m_State=E_Running;
653     return true;
654 }
655
656 bool
657 IsoHandlerManager::disable(IsoHandler *h) {
658     bool result;
659     int i=0;
660     debugOutput(DEBUG_LEVEL_VERBOSE, "Disable on IsoHandler %p\n", h);
661     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
662         it != m_IsoHandlers.end();
663         ++it )
664     {
665         if ((*it) == h) {
666             result = h->disable();
667             if(h->getType() == IsoHandler::eHT_Transmit) {
668                 result &= m_IsoTaskTransmit->requestShadowMapUpdate();
669             } else {
670                 result &= m_IsoTaskReceive->requestShadowMapUpdate();
671             }
672             debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " disabled\n");
673             return result;
674         }
675         i++;
676     }
677     debugError("Handler not found\n");
678     return false;
679 }
680
681 bool
682 IsoHandlerManager::enable(IsoHandler *h) {
683     bool result;
684     int i=0;
685     debugOutput(DEBUG_LEVEL_VERBOSE, "Enable on IsoHandler %p\n", h);
686     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
687         it != m_IsoHandlers.end();
688         ++it )
689     {
690         if ((*it) == h) {
691             result = h->enable();
692             if(h->getType() == IsoHandler::eHT_Transmit) {
693                 result &= m_IsoTaskTransmit->requestShadowMapUpdate();
694             } else {
695                 result &= m_IsoTaskReceive->requestShadowMapUpdate();
696             }
697             debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " enabled\n");
698             return result;
699         }
700         i++;
701     }
702     debugError("Handler not found\n");
703     return false;
704 }
705
706 void
707 IsoHandlerManager::signalActivityTransmit()
708 {
709     assert(m_IsoTaskTransmit);
710     m_IsoTaskTransmit->signalActivity();
711 }
712
713 void
714 IsoHandlerManager::signalActivityReceive()
715 {
716     assert(m_IsoTaskReceive);
717     m_IsoTaskReceive->signalActivity();
718 }
719
720 bool IsoHandlerManager::registerHandler(IsoHandler *handler)
721 {
722     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
723     assert(handler);
724     handler->setVerboseLevel(getDebugLevel());
725     m_IsoHandlers.push_back(handler);
726     requestShadowMapUpdate();
727     return true;
728 }
729
730 bool IsoHandlerManager::unregisterHandler(IsoHandler *handler)
731 {
732     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
733     assert(handler);
734
735     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
736       it != m_IsoHandlers.end();
737       ++it )
738     {
739         if ( *it == handler ) {
740             m_IsoHandlers.erase(it);
741             requestShadowMapUpdate();
742             return true;
743         }
744     }
745     debugFatal("Could not find handler (%p)\n", handler);
746     return false; //not found
747 }
748
749 /**
750  * Registers an StreamProcessor with the IsoHandlerManager.
751  *
752  * If nescessary, an IsoHandler is created to handle this stream.
753  * Once an StreamProcessor is registered to the handler, it will be included
754  * in the ISO streaming cycle (i.e. receive/transmit of it will occur).
755  *
756  * @param stream the stream to register
757  * @return true if registration succeeds
758  *
759  * \todo : currently there is a one-to-one mapping
760  *        between streams and handlers, this is not ok for
761  *        multichannel receive
762  */
763 bool IsoHandlerManager::registerStream(StreamProcessor *stream)
764 {
765     debugOutput( DEBUG_LEVEL_VERBOSE, "Registering %s stream %p\n", stream->getTypeString(), stream);
766     assert(stream);
767
768     IsoHandler* h = NULL;
769
770     // make sure the stream isn't already attached to a handler
771     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
772       it != m_IsoHandlers.end();
773       ++it )
774     {
775         if((*it)->isStreamRegistered(stream)) {
776             debugError( "stream already registered!\n");
777             return false;
778         }
779     }
780
781     // clean up all handlers that aren't used
782     pruneHandlers();
783
784     // allocate a handler for this stream
785     if (stream->getType()==StreamProcessor::ePT_Receive) {
786         // grab the options from the parent
787         Util::Configuration *config = m_service.getConfiguration();
788         int receive_mode_setting = DEFAULT_ISO_RECEIVE_MODE;
789         int bufferfill_mode_threshold = BUFFERFILL_MODE_THRESHOLD;
790         int min_interrupts_per_period = MINIMUM_INTERRUPTS_PER_PERIOD;
791         int max_nb_buffers_recv = MAX_RECV_NB_BUFFERS;
792         if(config) {
793             config->getValueForSetting("ieee1394.isomanager.iso_receive_mode", receive_mode_setting);
794             config->getValueForSetting("ieee1394.isomanager.bufferfill_mode_threshold", bufferfill_mode_threshold);
795             config->getValueForSetting("ieee1394.isomanager.min_interrupts_per_period", min_interrupts_per_period);
796             config->getValueForSetting("ieee1394.isomanager.max_nb_buffers_recv", max_nb_buffers_recv);
797         }
798
799         // setup the optimal parameters for the raw1394 ISO buffering
800         unsigned int packets_per_period = stream->getPacketsPerPeriod();
801         unsigned int max_packet_size = stream->getMaxPacketSize() + 8; // bufferfill takes another 8 bytes for headers
802         unsigned int page_size = getpagesize();
803
804         enum raw1394_iso_dma_recv_mode receive_mode;
805         switch(receive_mode_setting) {
806             case 0:
807                 if(packets_per_period < (unsigned)bufferfill_mode_threshold) {
808                     debugOutput( DEBUG_LEVEL_VERBOSE, "Using packet-per-buffer mode (auto) [%d, %d]\n",
809                                  packets_per_period, bufferfill_mode_threshold);
810                     receive_mode = RAW1394_DMA_PACKET_PER_BUFFER;
811                 } else {
812                     debugOutput( DEBUG_LEVEL_VERBOSE, "Using bufferfill mode (auto) [%d, %d]\n",
813                                  packets_per_period, bufferfill_mode_threshold);
814                     receive_mode = RAW1394_DMA_BUFFERFILL;
815                 }
816                 break;
817             case 1:
818                 debugOutput( DEBUG_LEVEL_VERBOSE, "Using packet-per-buffer mode (config)\n");
819                 receive_mode = RAW1394_DMA_PACKET_PER_BUFFER;
820                 break;
821             case 2:
822                 debugOutput( DEBUG_LEVEL_VERBOSE, "Using bufferfill mode (config)\n");
823                 receive_mode = RAW1394_DMA_BUFFERFILL;
824                 break;
825             default: debugWarning("Bogus receive mode setting in config: %d\n", receive_mode_setting);
826         }
827
828         // Ensure we don't request a packet size bigger than the
829         // kernel-enforced maximum which is currently 1 page.
830         // NOTE: PP: this is not really true AFAICT
831         if (max_packet_size > page_size) {
832             debugError("max packet size (%u) > page size (%u)\n", max_packet_size, page_size);
833             return false;
834         }
835
836         // the interrupt/wakeup interval prediction of raw1394 is a mess...
837         int irq_interval = (packets_per_period-1) / min_interrupts_per_period;
838         if(irq_interval <= 0) irq_interval=1;
839
840         // the receive buffer size doesn't matter for the latency,
841         // but it has a minimal value in order for libraw to operate correctly (300)
842         int buffers=1;
843         while(buffers < (int)packets_per_period && buffers < max_nb_buffers_recv) {
844             buffers *= 2;
845         }
846
847         // ensure at least 2 hardware interrupts per ISO buffer wraparound
848         if(irq_interval > buffers/2) {
849             irq_interval = buffers/2;
850         }
851
852         // create the actual handler
853         debugOutput( DEBUG_LEVEL_VERBOSE, " creating IsoRecvHandler\n");
854         h = new IsoHandler(*this, IsoHandler::eHT_Receive,
855                            buffers, max_packet_size, irq_interval);
856
857         if(!h) {
858             debugFatal("Could not create IsoRecvHandler\n");
859             return false;
860         }
861
862         h->setReceiveMode(receive_mode);
863
864     } else if (stream->getType()==StreamProcessor::ePT_Transmit) {
865         // grab the options from the parent
866         Util::Configuration *config = m_service.getConfiguration();
867         int min_interrupts_per_period = MINIMUM_INTERRUPTS_PER_PERIOD;
868         int max_nb_buffers_xmit = MAX_XMIT_NB_BUFFERS;
869         int max_packetsize_xmit = MAX_XMIT_PACKET_SIZE;
870         if(config) {
871             config->getValueForSetting("ieee1394.isomanager.min_interrupts_per_period", min_interrupts_per_period);
872             config->getValueForSetting("ieee1394.isomanager.max_nb_buffers_xmit", max_nb_buffers_xmit);
873             config->getValueForSetting("ieee1394.isomanager.max_packetsize_xmit", max_packetsize_xmit);
874         }
875
876         // setup the optimal parameters for the raw1394 ISO buffering
877         unsigned int max_packet_size = stream->getMaxPacketSize();
878
879         if (max_packet_size > (unsigned)max_packetsize_xmit) {
880             debugError("max packet size (%u) > MAX_XMIT_PACKET_SIZE (%u)\n",
881                        max_packet_size, max_packetsize_xmit);
882             return false;
883         }
884
885         // the SP specifies how many packets to ISO-buffer
886         int req_buffers = stream->getNbPacketsIsoXmitBuffer();
887         int buffers=1;
888         while(buffers < (int)req_buffers && buffers < max_nb_buffers_xmit) {
889             buffers *= 2;
890         }
891
892         int irq_interval = req_buffers / min_interrupts_per_period;
893         if(irq_interval <= 0) irq_interval = 1;
894         // ensure at least 2 hardware interrupts per ISO buffer wraparound
895         if(irq_interval > buffers/2) irq_interval = buffers/2;
896
897         debugOutput( DEBUG_LEVEL_VERBOSE, " creating IsoXmitHandler\n");
898
899         // create the actual handler
900         h = new IsoHandler(*this, IsoHandler::eHT_Transmit,
901                            buffers, max_packet_size, irq_interval);
902
903         if(!h) {
904             debugFatal("Could not create IsoXmitHandler\n");
905             return false;
906         }
907
908     } else {
909         debugFatal("Bad stream type\n");
910         return false;
911     }
912
913     h->setVerboseLevel(getDebugLevel());
914
915     // init the handler
916     if(!h->init()) {
917         debugFatal("Could not initialize receive handler\n");
918         return false;
919     }
920
921     // register the stream with the handler
922     if(!h->registerStream(stream)) {
923         debugFatal("Could not register receive stream with handler\n");
924         return false;
925     }
926
927     // register the handler with the manager
928     if(!registerHandler(h)) {
929         debugFatal("Could not register receive handler with manager\n");
930         return false;
931     }
932     debugOutput( DEBUG_LEVEL_VERBOSE, " registered stream (%p) with handler (%p)\n", stream, h);
933
934     m_StreamProcessors.push_back(stream);
935     debugOutput( DEBUG_LEVEL_VERBOSE, " %d streams, %d handlers registered\n",
936                                       m_StreamProcessors.size(), m_IsoHandlers.size());
937     return true;
938 }
939
940 bool IsoHandlerManager::unregisterStream(StreamProcessor *stream)
941 {
942     debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering %s stream %p\n", stream->getTypeString(), stream);
943     assert(stream);
944
945     // make sure the stream isn't attached to a handler anymore
946     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
947       it != m_IsoHandlers.end();
948       ++it )
949     {
950         if((*it)->isStreamRegistered(stream)) {
951             if(!(*it)->unregisterStream(stream)) {
952                 debugOutput( DEBUG_LEVEL_VERBOSE, " could not unregister stream (%p) from handler (%p)...\n",stream,*it);
953                 return false;
954             }
955             debugOutput( DEBUG_LEVEL_VERBOSE, " unregistered stream (%p) from handler (%p)...\n",stream,*it);
956         }
957     }
958
959     // clean up all handlers that aren't used
960     pruneHandlers();
961
962     // remove the stream from the registered streams list
963     for ( StreamProcessorVectorIterator it = m_StreamProcessors.begin();
964       it != m_StreamProcessors.end();
965       ++it )
966     {
967         if ( *it == stream ) {
968             m_StreamProcessors.erase(it);
969             debugOutput( DEBUG_LEVEL_VERBOSE, " deleted stream (%p) from list...\n", *it);
970             return true;
971         }
972     }
973     return false; //not found
974 }
975
976 /**
977  * @brief unregister a handler from the manager
978  * @note called without the lock held.
979  */
980 void IsoHandlerManager::pruneHandlers() {
981     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
982     IsoHandlerVector toUnregister;
983
984     // find all handlers that are not in use
985     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
986           it != m_IsoHandlers.end();
987           ++it )
988     {
989         if(!((*it)->inUse())) {
990             debugOutput( DEBUG_LEVEL_VERBOSE, " handler (%p) not in use\n",*it);
991             toUnregister.push_back(*it);
992         }
993     }
994     // delete them
995     for ( IsoHandlerVectorIterator it = toUnregister.begin();
996           it != toUnregister.end();
997           ++it )
998     {
999         unregisterHandler(*it);
1000
1001         debugOutput( DEBUG_LEVEL_VERBOSE, " deleting handler (%p)\n",*it);
1002
1003         // Now the handler's been unregistered it won't be reused
1004         // again.  Therefore it really needs to be formally deleted
1005         // to free up the raw1394 handle.  Otherwise things fall
1006         // apart after several xrun recoveries as the system runs
1007         // out of resources to support all the disused but still
1008         // allocated raw1394 handles.  At least this is the current
1009         // theory as to why we end up with "memory allocation"
1010         // failures after several Xrun recoveries.
1011         delete *it;
1012     }
1013 }
1014
1015 bool
1016 IsoHandlerManager::stopHandlerForStream(Streaming::StreamProcessor *stream) {
1017     // check state
1018     if(m_State != E_Running) {
1019         debugError("Incorrect state, expected E_Running, got %s\n", eHSToString(m_State));
1020         return false;
1021     }
1022     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1023       it != m_IsoHandlers.end();
1024       ++it )
1025     {
1026         if((*it)->isStreamRegistered(stream)) {
1027             debugOutput( DEBUG_LEVEL_VERBOSE, " stopping handler %p for stream %p\n", *it, stream);
1028             if(!(*it)->disable()) {
1029                 debugOutput( DEBUG_LEVEL_VERBOSE, " could not disable handler (%p)\n",*it);
1030                 return false;
1031             }
1032             bool result;
1033             if((*it)->getType() == IsoHandler::eHT_Transmit) {
1034                 result = m_IsoTaskTransmit->requestShadowMapUpdate();
1035             } else {
1036                 result = m_IsoTaskReceive->requestShadowMapUpdate();
1037             }
1038             if(!result) {
1039                 debugOutput( DEBUG_LEVEL_VERBOSE, " could not update shadow map for handler (%p)\n",*it);
1040                 return false;
1041             }
1042             return true;
1043         }
1044     }
1045     debugError("Stream %p has no attached handler\n", stream);
1046     return false;
1047 }
1048
1049 int
1050 IsoHandlerManager::getPacketLatencyForStream(Streaming::StreamProcessor *stream) {
1051     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1052       it != m_IsoHandlers.end();
1053       ++it )
1054     {
1055         if((*it)->isStreamRegistered(stream)) {
1056             return (*it)->getIrqInterval();
1057         }
1058     }
1059     debugError("Stream %p has no attached handler\n", stream);
1060     return 0;
1061 }
1062
1063 void
1064 IsoHandlerManager::flushHandlerForStream(Streaming::StreamProcessor *stream) {
1065     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1066       it != m_IsoHandlers.end();
1067       ++it )
1068     {
1069         if((*it)->isStreamRegistered(stream)) {
1070             (*it)->flush();
1071         }
1072     }
1073     debugError("Stream %p has no attached handler\n", stream);
1074     return;
1075 }
1076
1077 IsoHandler *
1078 IsoHandlerManager::getHandlerForStream(Streaming::StreamProcessor *stream) {
1079     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1080       it != m_IsoHandlers.end();
1081       ++it )
1082     {
1083         if((*it)->isStreamRegistered(stream)) {
1084             return (*it);
1085         }
1086     }
1087     debugError("Stream %p has no attached handler\n", stream);
1088     return NULL;
1089 }
1090
1091 bool
1092 IsoHandlerManager::startHandlerForStream(Streaming::StreamProcessor *stream) {
1093     return startHandlerForStream(stream, -1);
1094 }
1095
1096 bool
1097 IsoHandlerManager::startHandlerForStream(Streaming::StreamProcessor *stream, int cycle) {
1098     // check state
1099     if(m_State != E_Running) {
1100         debugError("Incorrect state, expected E_Running, got %s\n", eHSToString(m_State));
1101         return false;
1102     }
1103     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1104       it != m_IsoHandlers.end();
1105       ++it )
1106     {
1107         if((*it)->isStreamRegistered(stream)) {
1108             debugOutput( DEBUG_LEVEL_VERBOSE, " starting handler %p for stream %p\n", *it, stream);
1109             if(!(*it)->enable(cycle)) {
1110                 debugOutput( DEBUG_LEVEL_VERBOSE, " could not enable handler (%p)\n",*it);
1111                 return false;
1112             }
1113             bool result;
1114             if((*it)->getType() == IsoHandler::eHT_Transmit) {
1115                 result = m_IsoTaskTransmit->requestShadowMapUpdate();
1116             } else {
1117                 result = m_IsoTaskReceive->requestShadowMapUpdate();
1118             }
1119             if(!result) {
1120                 debugOutput( DEBUG_LEVEL_VERBOSE, " could not update shadow map for handler (%p)\n",*it);
1121                 return false;
1122             }
1123             return true;
1124         }
1125     }
1126     debugError("Stream %p has no attached handler\n", stream);
1127     return false;
1128 }
1129
1130 bool IsoHandlerManager::stopHandlers() {
1131     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
1132
1133     // check state
1134     if(m_State != E_Running) {
1135         debugError("Incorrect state, expected E_Running, got %s\n", eHSToString(m_State));
1136         return false;
1137     }
1138
1139     bool retval=true;
1140
1141     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1142         it != m_IsoHandlers.end();
1143         ++it )
1144     {
1145         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handler (%p)\n",*it);
1146         if(!(*it)->disable()){
1147             debugOutput( DEBUG_LEVEL_VERBOSE, " could not stop handler (%p)\n",*it);
1148             retval=false;
1149         }
1150         bool result;
1151         if((*it)->getType() == IsoHandler::eHT_Transmit) {
1152             result = m_IsoTaskTransmit->requestShadowMapUpdate();
1153         } else {
1154             result = m_IsoTaskReceive->requestShadowMapUpdate();
1155         }
1156         if(!result) {
1157             debugOutput( DEBUG_LEVEL_VERBOSE, " could not update shadow map for handler (%p)\n",*it);
1158             return false;
1159         }
1160     }
1161
1162     if (retval) {
1163         m_State=E_Prepared;
1164     } else {
1165         m_State=E_Error;
1166     }
1167     return retval;
1168 }
1169
1170 bool IsoHandlerManager::reset() {
1171     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n");
1172     // check state
1173     if(m_State == E_Error) {
1174         debugFatal("Resetting from error condition not yet supported...\n");
1175         return false;
1176     }
1177     // if not in an error condition, reset means stop the handlers
1178     return stopHandlers();
1179 }
1180
1181 void IsoHandlerManager::setVerboseLevel(int i) {
1182     setDebugLevel(i);
1183     // propagate the debug level
1184     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1185           it != m_IsoHandlers.end();
1186           ++it )
1187     {
1188         (*it)->setVerboseLevel(i);
1189     }
1190     if(m_IsoThreadTransmit) m_IsoThreadTransmit->setVerboseLevel(i);
1191     if(m_IsoTaskTransmit)   m_IsoTaskTransmit->setVerboseLevel(i);
1192     if(m_IsoThreadReceive)  m_IsoThreadReceive->setVerboseLevel(i);
1193     if(m_IsoTaskReceive)    m_IsoTaskReceive->setVerboseLevel(i);
1194     setDebugLevel(i);
1195     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", i );
1196 }
1197
1198 void IsoHandlerManager::dumpInfo() {
1199     #ifdef DEBUG
1200     unsigned int i=0;
1201     debugOutputShort( DEBUG_LEVEL_NORMAL, "Dumping IsoHandlerManager Stream handler information...\n");
1202     debugOutputShort( DEBUG_LEVEL_NORMAL, " State: %d\n",(int)m_State);
1203
1204     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin();
1205           it != m_IsoHandlers.end();
1206           ++it )
1207     {
1208         debugOutputShort( DEBUG_LEVEL_NORMAL, " IsoHandler %d (%p)\n",i++,*it);
1209         (*it)->dumpInfo();
1210     }
1211     #endif
1212 }
1213
1214 const char *
1215 IsoHandlerManager::eHSToString(enum eHandlerStates s) {
1216     switch (s) {
1217         default: return "Invalid";
1218         case E_Created: return "Created";
1219         case E_Prepared: return "Prepared";
1220         case E_Running: return "Running";
1221         case E_Error: return "Error";
1222     }
1223 }
Note: See TracBrowser for help on using the browser.