1 |
/* freebob.cpp |
---|
2 |
* Copyright (C) 2005 Pieter Palmers, Daniel Wagner |
---|
3 |
* |
---|
4 |
* This file is part of FreeBoB |
---|
5 |
* |
---|
6 |
* This library is free software; you can redistribute it and/or |
---|
7 |
* modify it under the terms of the GNU Lesser General Public |
---|
8 |
* License as published by the Free Software Foundation; either |
---|
9 |
* version 2.1 of the License, or (at your option) any later version. |
---|
10 |
* |
---|
11 |
* This library is distributed in the hope that it will be useful, |
---|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 |
* Lesser General Public License for more details. |
---|
15 |
* |
---|
16 |
* You should have received a copy of the GNU Lesser General Public |
---|
17 |
* License along with this library; if not, write to the Free Software |
---|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
19 |
* MA 02110-1301 USA |
---|
20 |
*/ |
---|
21 |
|
---|
22 |
#include "config.h" |
---|
23 |
|
---|
24 |
#include "libfreebob/freebob.h" |
---|
25 |
|
---|
26 |
#include "debugmodule/debugmodule.h" |
---|
27 |
#include "fbtypes.h" |
---|
28 |
#include "devicemanager.h" |
---|
29 |
#include "iavdevice.h" |
---|
30 |
|
---|
31 |
#include "libavc/avc_generic.h" |
---|
32 |
|
---|
33 |
#include <stdio.h> |
---|
34 |
#include <stdlib.h> |
---|
35 |
#include <string.h> |
---|
36 |
|
---|
37 |
DECLARE_GLOBAL_DEBUG_MODULE; |
---|
38 |
IMPL_GLOBAL_DEBUG_MODULE( FreeBoB, DEBUG_LEVEL_VERBOSE ); |
---|
39 |
|
---|
40 |
#ifdef __cplusplus |
---|
41 |
extern "C" { |
---|
42 |
#endif |
---|
43 |
|
---|
44 |
// this is very much nescessary, as otherwise the |
---|
45 |
// message buffer thread doesn't get killed when the |
---|
46 |
// library is dlclose()'d |
---|
47 |
|
---|
48 |
static void exitfunc(void) __attribute__((destructor)); |
---|
49 |
|
---|
50 |
static void exitfunc(void) |
---|
51 |
{ |
---|
52 |
delete DebugModuleManager::instance(); |
---|
53 |
|
---|
54 |
} |
---|
55 |
#ifdef __cplusplus |
---|
56 |
} |
---|
57 |
#endif |
---|
58 |
|
---|
59 |
const char* |
---|
60 |
freebob_get_version() { |
---|
61 |
return PACKAGE_STRING; |
---|
62 |
} |
---|
63 |
|
---|
64 |
|
---|
65 |
int |
---|
66 |
freebob_get_api_version() { |
---|
67 |
return FREEBOB_API_VERSION; |
---|
68 |
} |
---|
69 |
|
---|
70 |
freebob_handle_t |
---|
71 |
freebob_new_handle( int port ) |
---|
72 |
{ |
---|
73 |
freebob_handle_t handle = new struct freebob_handle; |
---|
74 |
if (! handle ) { |
---|
75 |
debugFatal( "Could not allocate memory for new handle\n" ); |
---|
76 |
return 0; |
---|
77 |
} |
---|
78 |
|
---|
79 |
handle->m_deviceManager = new DeviceManager(); |
---|
80 |
if ( !handle->m_deviceManager ) { |
---|
81 |
debugFatal( "Could not allocate device manager\n" ); |
---|
82 |
delete handle; |
---|
83 |
return 0; |
---|
84 |
} |
---|
85 |
if ( !handle->m_deviceManager->initialize( port ) ) { |
---|
86 |
debugFatal( "Could not initialize device manager\n" ); |
---|
87 |
delete handle->m_deviceManager; |
---|
88 |
delete handle; |
---|
89 |
return 0; |
---|
90 |
} |
---|
91 |
return handle; |
---|
92 |
} |
---|
93 |
|
---|
94 |
int |
---|
95 |
freebob_destroy_handle( freebob_handle_t freebob_handle ) |
---|
96 |
{ |
---|
97 |
delete freebob_handle->m_deviceManager; |
---|
98 |
delete freebob_handle; |
---|
99 |
return 0; |
---|
100 |
} |
---|
101 |
|
---|
102 |
int |
---|
103 |
freebob_discover_devices( freebob_handle_t freebob_handle, int verbose ) |
---|
104 |
{ |
---|
105 |
if (verbose) { |
---|
106 |
freebob_handle->m_deviceManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); |
---|
107 |
} |
---|
108 |
return freebob_handle->m_deviceManager->discover()? 0 : -1; |
---|
109 |
} |
---|
110 |
|
---|
111 |
int |
---|
112 |
freebob_node_is_valid_freebob_device( freebob_handle_t freebob_handle, int node_id ) |
---|
113 |
{ |
---|
114 |
return freebob_handle->m_deviceManager->isValidNode( node_id ); |
---|
115 |
} |
---|
116 |
|
---|
117 |
int |
---|
118 |
freebob_get_nb_devices_on_bus( freebob_handle_t freebob_handle ) |
---|
119 |
{ |
---|
120 |
return freebob_handle->m_deviceManager->getNbDevices(); |
---|
121 |
} |
---|
122 |
|
---|
123 |
int |
---|
124 |
freebob_get_device_node_id( freebob_handle_t freebob_handle, int device_nr ) |
---|
125 |
{ |
---|
126 |
return freebob_handle->m_deviceManager->getDeviceNodeId(device_nr); |
---|
127 |
} |
---|
128 |
|
---|
129 |
int |
---|
130 |
freebob_set_samplerate( freebob_handle_t freebob_handle, int node_id, int samplerate ) |
---|
131 |
{ |
---|
132 |
IAvDevice* avDevice = freebob_handle->m_deviceManager->getAvDevice( node_id ); |
---|
133 |
if ( avDevice ) { |
---|
134 |
if ( avDevice->setSamplingFrequency( parseSampleRate( samplerate ) ) ) { |
---|
135 |
return freebob_handle->m_deviceManager->discover()? 0 : -1; |
---|
136 |
} |
---|
137 |
} |
---|
138 |
return -1; |
---|
139 |
} |
---|
140 |
|
---|
141 |
void freebob_sleep_after_avc_command( int time ) |
---|
142 |
{ |
---|
143 |
AVCCommand::setSleepAfterAVCCommand( time ); |
---|
144 |
} |
---|