/*
 WebRTCDeviceService.java
 Copyright (c) 2015 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */
package org.deviceconnect.android.deviceplugin.webrtc;

import org.deviceconnect.android.deviceplugin.webrtc.profile.WebRTCSystemProfile;
import org.deviceconnect.android.deviceplugin.webrtc.service.WebRTCService;
import org.deviceconnect.android.deviceplugin.webrtc.util.WebRTCManager;
import org.deviceconnect.android.event.EventManager;
import org.deviceconnect.android.event.cache.MemoryCacheController;
import org.deviceconnect.android.message.DConnectMessageService;
import org.deviceconnect.android.profile.SystemProfile;

/**
 * WebRTC device plug-in.
 *
 * @author NTT DOCOMO, INC.
 */
public class WebRTCDeviceService extends DConnectMessageService {

    private WebRTCManager mWebRTCManager;

    @Override
    public void onCreate() {
        super.onCreate();
        EventManager.INSTANCE.setController(new MemoryCacheController());
        mWebRTCManager = new WebRTCManager((WebRTCApplication) getApplication());
        getServiceProvider().addService(new WebRTCService((WebRTCApplication) getApplication()));
    }

    @Override
    public void onDestroy() {
        if (mWebRTCManager != null) {
            mWebRTCManager.destroy();
            mWebRTCManager = null;
        }
        super.onDestroy();
    }

    @Override
    protected void onManagerUninstalled() {
        // Managerアンインストール検知時の処理。
    }

    @Override
    protected void onManagerTerminated() {
        // Manager正常終了通知受信時の処理。
    }

    @Override
    protected void onManagerEventTransmitDisconnected(String sessionKey) {
        // ManagerのEvent送信経路切断通知受信時の処理。
        if (sessionKey != null) {
            EventManager.INSTANCE.removeEvents(sessionKey);
        } else {
            EventManager.INSTANCE.removeAll();
        }
    }

    @Override
    protected void onDevicePluginReset() {
        // Device Plug-inへのReset要求受信時の処理。
        resetPluginResource();
    }

    /**
     * リソースリセット処理.
     */
    private void resetPluginResource() {
        /** 全イベント削除. */
        EventManager.INSTANCE.removeAll();

        /** Peer切断処理. */
        WebRTCApplication app = (WebRTCApplication) ((DConnectMessageService) getContext()).getApplication();
        if (app != null) {
            app.destroyPeer();
        }
    }

    @Override
    protected SystemProfile getSystemProfile() {
        return new WebRTCSystemProfile();
    }

    public WebRTCManager getWebRTCManager() {
        return mWebRTCManager;
    }
}

@@ -672,16 +672,50 @@
 ofile;%0A%0A
+import java.util.logging.Logger;%0A%0A
 /**%0A * W
@@ -838,16 +838,104 @@
 vice %7B%0A%0A
+    /** %E3%83%AD%E3%82%AC%E3%83%BC. */%0A    private final Logger mLogger = Logger.getLogger(%22webrtc.dplugin%22);%0A%0A
     priv
@@ -1598,99 +1598,304 @@
     
-%7D%0A%0A    @Override%0A    protected void onManagerTerminated() %7B%0A        // Manager%E6%AD%A3%E5%B8%B8%E7%B5%82%E4%BA%86%E9%80%9A%E7%9F%A5%E5%8F%97%E4%BF%A1%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86%E3%80%82
+    if (BuildConfig.DEBUG) %7B%0A            mLogger.info(%22Plug-in : onManagerUninstalled%22);%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected void onManagerTerminated() %7B%0A        // Manager%E6%AD%A3%E5%B8%B8%E7%B5%82%E4%BA%86%E9%80%9A%E7%9F%A5%E5%8F%97%E4%BF%A1%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86%E3%80%82%0A        if (BuildConfig.DEBUG) %7B%0A            mLogger.info(%22Plug-in : onManagerTerminated%22);%0A        %7D
 %0A   
@@ -2019,32 +2019,149 @@
 %E9%80%81%E4%BF%A1%E7%B5%8C%E8%B7%AF%E5%88%87%E6%96%AD%E9%80%9A%E7%9F%A5%E5%8F%97%E4%BF%A1%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86%E3%80%82%0A
+        if (BuildConfig.DEBUG) %7B%0A            mLogger.info(%22Plug-in : onManagerEventTransmitDisconnected%22);%0A        %7D%0A
         if (sess
@@ -2410,32 +2410,134 @@
 %E3%81%AEReset%E8%A6%81%E6%B1%82%E5%8F%97%E4%BF%A1%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86%E3%80%82%0A
+        if (BuildConfig.DEBUG) %7B%0A            mLogger.info(%22Plug-in : onDevicePluginReset%22);%0A        %7D%0A
         resetPlu

デバッグ用ログ追加。