OSDN Git Service

安定性調査中。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / nikon / wrapper / NikonInterfaceProvider.java
1 package net.osdn.gokigen.a01d.camera.nikon.wrapper;
2
3 import android.app.Activity;
4 import android.util.Log;
5
6 import androidx.annotation.NonNull;
7
8 import net.osdn.gokigen.a01d.IInformationReceiver;
9 import net.osdn.gokigen.a01d.camera.ICameraConnection;
10 import net.osdn.gokigen.a01d.camera.ICameraInformation;
11 import net.osdn.gokigen.a01d.camera.ICameraStatus;
12 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
13 import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
14 import net.osdn.gokigen.a01d.camera.ICaptureControl;
15 import net.osdn.gokigen.a01d.camera.IDisplayInjector;
16 import net.osdn.gokigen.a01d.camera.IFocusingControl;
17 import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
18 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
19 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
20 import net.osdn.gokigen.a01d.camera.nikon.operation.NikonCaptureControl;
21 import net.osdn.gokigen.a01d.camera.nikon.operation.NikonFocusingControl;
22 import net.osdn.gokigen.a01d.camera.nikon.operation.NikonZoomLensControl;
23 import net.osdn.gokigen.a01d.camera.nikon.wrapper.connection.NikonConnection;
24 import net.osdn.gokigen.a01d.camera.nikon.wrapper.hardware.NikonCameraInformation;
25 import net.osdn.gokigen.a01d.camera.nikon.wrapper.liveview.NikonLiveViewControl;
26 import net.osdn.gokigen.a01d.camera.nikon.wrapper.status.NikonStatusChecker;
27 import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
28 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
29 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
30 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
31 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
32 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
33 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.IPtpIpRunModeHolder;
34 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.PtpIpRunMode;
35 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
36 import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
37 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
38 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
39
40 public class NikonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplayInjector
41 {
42     private final String TAG = toString();
43
44     private static final int ASYNC_RESPONSE_PORT = 15741;
45     private static final int CONTROL_PORT = 15740;
46     private static final int EVENT_PORT = 15740;
47     private static final String CAMERA_IP = "192.168.1.1";
48
49     private final Activity activity;
50     private final PtpIpRunMode runmode;
51     private final NikonCameraInformation cameraInformation;
52     private NikonCaptureControl captureControl;
53     private NikonFocusingControl focusingControl;
54     private NikonConnection canonConnection;
55     private PtpIpCommandPublisher commandPublisher;
56     private NikonLiveViewControl liveViewControl;
57     private PtpIpAsyncResponseReceiver asyncReceiver;
58     private NikonZoomLensControl zoomControl;
59     private NikonStatusChecker statusChecker;
60     private ICameraStatusUpdateNotify statusListener;
61     private IInformationReceiver informationReceiver;
62
63     public NikonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
64     {
65         this.activity = context;
66         commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, false);
67         liveViewControl = new NikonLiveViewControl(context, this, 20);
68         asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
69         statusChecker = new NikonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
70         canonConnection = new NikonConnection(context, provider, this, statusChecker);
71         cameraInformation = new NikonCameraInformation();
72         zoomControl = new NikonZoomLensControl();
73         this.statusListener = statusListener;
74         this.runmode = new PtpIpRunMode();
75         this.informationReceiver = informationReceiver;
76     }
77
78     @Override
79     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
80     {
81         Log.v(TAG, "injectDisplay()");
82         captureControl = new NikonCaptureControl(commandPublisher, frameDisplayer);
83         focusingControl = new NikonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
84     }
85
86     @Override
87     public ICameraConnection getCameraConnection()
88     {
89         return (canonConnection);
90     }
91
92     @Override
93     public ILiveViewControl getLiveViewControl()
94     {
95         return (liveViewControl);
96     }
97
98     @Override
99     public ILiveViewListener getLiveViewListener()
100     {
101         return (liveViewControl.getLiveViewListener());
102     }
103
104     @Override
105     public IFocusingControl getFocusingControl()
106     {
107         return (focusingControl);
108     }
109
110     @Override
111     public ICameraInformation getCameraInformation()
112     {
113         return (cameraInformation);
114     }
115
116     @Override
117     public IZoomLensControl getZoomLensControl()
118     {
119         return (zoomControl);
120     }
121
122     @Override
123     public ICaptureControl getCaptureControl()
124     {
125         return (captureControl);
126     }
127
128     @Override
129     public IDisplayInjector getDisplayInjector()
130     {
131         return (this);
132     }
133
134     @Override
135     public IPtpIpRunModeHolder getRunModeHolder()
136     {
137         return (runmode);
138     }
139
140     @Override
141     public IPtpIpCommandCallback getStatusHolder() {
142         return (statusChecker);
143     }
144
145     @Override
146     public IPtpIpCommandPublisher getCommandPublisher()
147     {
148         return (commandPublisher);
149     }
150
151     @Override
152     public IPtpIpCommunication getLiveviewCommunication()
153     {
154         return (liveViewControl);
155     }
156
157     @Override
158     public IPtpIpCommunication getAsyncEventCommunication()
159     {
160         return (asyncReceiver);
161     }
162
163     @Override
164     public IPtpIpCommunication getCommandCommunication()
165     {
166         return (commandPublisher);
167     }
168
169     @Override
170     public ICameraStatusWatcher getCameraStatusWatcher()
171     {
172         return (statusChecker);
173     }
174
175     @Override
176     public ICameraStatusUpdateNotify getStatusListener()
177     {
178         return (statusListener);
179     }
180
181     @Override
182     public ICameraStatus getCameraStatusListHolder()
183     {
184         return (statusChecker);
185     }
186
187     @Override
188     public IInformationReceiver getInformationReceiver()
189     {
190         // ちょっとこの引き回しは気持ちがよくない...
191         return (informationReceiver);
192     }
193
194     @Override
195     public ICameraStatusWatcher getStatusWatcher()
196     {
197         return (statusChecker);
198     }
199
200     @Override
201     public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
202     {
203         asyncReceiver.setEventSubscriber(receiver);
204     }
205
206 }