package org.wso2.carbon.device.mgt.ios.apns.internal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.ios.apns.service.PushNotificationService;
import org.wso2.carbon.device.mgt.ios.apns.service.impl.PushNotificationServiceImpl;

/**
 * @scr.component name="org.wso2.carbon.device.ios.apns" immediate="true"
 */
public class PushNotificationSenderServiceComponent {

    private static final Log log = LogFactory.getLog(PushNotificationSenderServiceComponent.class);

    protected void activate(ComponentContext componentContext) {

        try {
            if (log.isDebugEnabled()) {
                log.debug("Initializing iOS APNS core bundle");
            }

            BundleContext bundleContext = componentContext.getBundleContext();
            bundleContext.registerService(PushNotificationService.class.getName(),
                    new PushNotificationServiceImpl(), null);

            if (log.isDebugEnabled()) {
                log.debug("iOS device management core bundle has been successfully initialized");
            }
        } catch (Throwable e) {
            String msg = "Error occurred while initializing ios device management core bundle";
            log.error(msg, e);
        }
    }

    protected void deactivate(ComponentContext ctx) {
        if (log.isDebugEnabled()) {
            log.debug("Deactivating iOS APNS core bundle");
        }
    }
}
