2 * Copyright 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.bug.servicetracker;
19 import com.buglabs.application.AbstractServiceTracker;
20 import com.buglabs.bug.module.camera.pub.ICameraDevice;
21 import com.buglabs.bug.module.camera.pub.ICameraModuleControl;
22 import com.buglabs.bug.module.lcd.pub.IModuleDisplay;
23 import com.buglabs.device.IButtonEventProvider;
24 import com.google.zxing.client.bug.app.BugBarcodeApp;
25 import org.osgi.framework.BundleContext;
27 import java.awt.Frame;
28 import java.util.Collection;
31 * Service tracker for the BugApp Bundle
33 * @author David Albert
35 public final class BugBarcodeServiceTracker extends AbstractServiceTracker {
37 private IButtonEventProvider buttonEventProvider;
39 private BugBarcodeApp app;
41 public BugBarcodeServiceTracker(BundleContext context) {
46 public void doStart() {
47 IModuleDisplay display = (IModuleDisplay) getService(IModuleDisplay.class);
48 ICameraDevice camera = (ICameraDevice) getService(ICameraDevice.class);
49 ICameraModuleControl cameraControl = (ICameraModuleControl) getService(ICameraModuleControl.class);
50 buttonEventProvider = (IButtonEventProvider) getService(IButtonEventProvider.class);
51 frame = display.getFrame();
52 app = new BugBarcodeApp(frame, camera, cameraControl, buttonEventProvider);
56 * Called when a service that this application depends is unregistered.
59 public void doStop() {
60 buttonEventProvider.removeListener(app);
65 * Allows the user to set the service dependencies by
66 * adding them to services list returned by getServices().
67 * i.e.nl getServices().add(MyService.class.getName());
70 public void initServices() {
71 Collection<String> appServices = (Collection<String>) getServices();
72 appServices.add("com.buglabs.bug.module.camera.pub.ICameraDevice");
73 appServices.add("com.buglabs.bug.module.lcd.pub.IModuleDisplay");
74 appServices.add(IButtonEventProvider.class.getName());
75 appServices.add(ICameraModuleControl.class.getName());