2 * Copyright 2004-2008, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
14 #undef B_WEBCAM_MKINTFUNC
15 #define B_WEBCAM_MKINTFUNC(modname) \
16 extern "C" status_t get_webcam_addon_##modname(WebCamMediaAddOn* webcam, CamDeviceAddon **addon);
17 #include "CamInternalAddons.h"
18 #undef B_WEBCAM_MKINTFUNC
21 CamRoster::CamRoster(WebCamMediaAddOn
* _addon
)
23 fLocker("WebcamRosterLock"),
32 CamRoster::~CamRoster()
38 CamRoster::DeviceAdded(BUSBDevice
* _device
)
42 for (int16 i
= fCamerasAddons
.CountItems() - 1; i
>= 0; --i
) {
43 CamDeviceAddon
*ao
= (CamDeviceAddon
*)fCamerasAddons
.ItemAt(i
);
44 PRINT((CH
": checking %s for support..." CT
, ao
->BrandName()));
45 err
= ao
->Sniff(_device
);
48 CamDevice
*cam
= ao
->Instantiate(*this, _device
);
49 PRINT((CH
": found camera %s:%s!" CT
, cam
->BrandName(), cam
->ModelName()));
50 err
= cam
->InitCheck();
52 fCameras
.AddItem(cam
);
53 fAddon
->CameraAdded(cam
);
56 PRINT((CH
" error 0x%08lx" CT
, err
));
63 CamRoster::DeviceRemoved(BUSBDevice
* _device
)
66 for (int32 i
= 0; i
< fCameras
.CountItems(); ++i
) {
67 CamDevice
* cam
= (CamDevice
*)fCameras
.ItemAt(i
);
68 if (cam
->Matches(_device
)) {
69 PRINT((CH
": camera %s:%s removed" CT
, cam
->BrandName(), cam
->ModelName()));
70 fCameras
.RemoveItem(i
);
71 fAddon
->CameraRemoved(cam
);
72 // XXX: B_DONT_DO_THAT!
82 CamRoster::CountCameras()
86 PRINT((CH
"(): %ld cameras" CT
, fCameras
.CountItems()));
87 count
= fCameras
.CountItems();
97 return fLocker
.Lock();
111 CamRoster::CameraAt(int32 index
)
114 return (CamDevice
*)fCameras
.ItemAt(index
);
119 CamRoster::LoadInternalAddons()
122 CamDeviceAddon
*addon
;
125 #undef B_WEBCAM_MKINTFUNC
126 #define B_WEBCAM_MKINTFUNC(modname) \
127 err = get_webcam_addon_##modname(fAddon, &addon); \
129 fCamerasAddons.AddItem(addon); \
130 PRINT((CH ": registered %s addon" CT, addon->BrandName())); \
133 #include "CamInternalAddons.h"
134 #undef B_WEBCAM_MKINTFUNC
142 CamRoster::LoadExternalAddons()
150 CamDeviceAddon
*addon
;
151 status_t (*get_webcam_addon_func
)(WebCamMediaAddOn
* webcam
, CamDeviceAddon
**addon
);
152 for (index
= 0; get_nth_image_symbol(fAddon
->ImageID(),
155 (void **)&get_webcam_addon_func
) == B_OK
; index
++) {
156 PRINT((CH
": got sym" CT
));
157 // if (sclass != B_SYMBOL_TYPE_TEXT)
159 err
= (*get_webcam_addon_func
)(fAddon
, &addon
);
160 PRINT((CH
": Loaded addon '%s' with error 0x%08lx" CT
, (err
>0)?NULL
:addon
->BrandName(), err
));