Initial checkin of bug client code from buglabs
[zxing.git] / bug / src / com / google / zxing / client / bug / servicetracker / BugBarcodeServiceTracker.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.bug.servicetracker;
18
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;
26
27 import java.awt.Frame;
28 import java.util.Collection;
29
30 /**
31  * Service tracker for the BugApp Bundle
32  *
33  * @author David Albert
34  */
35 public final class BugBarcodeServiceTracker extends AbstractServiceTracker {
36
37   private IButtonEventProvider buttonEventProvider;
38         private Frame frame;
39         private BugBarcodeApp app;
40         
41         public BugBarcodeServiceTracker(BundleContext context) {
42                 super(context);
43         }
44
45         @Override
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);
53         }
54
55         /**
56          * Called when a service that this application depends is unregistered.
57          */
58         @Override
59   public void doStop() {
60                 buttonEventProvider.removeListener(app);
61                 frame.dispose();
62         }
63
64         /**
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());
68          */
69         @Override
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());
76         }
77         
78 }
79