/*
 * Copyright (c) 2016 Route1 Inc.  All rights reerved.  <sales@route1.com>
 * http://www.route1.com
 *
 * You may use, distribute and modify this code under the
 * terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This code is provided “as -is,” without warranty of any kind,
 * express, implied or statutory, including but not limited to
 * any implied warranties or conditions of quality, performance,
 * merchantability, merchantable quality, durability,
 * non-infringement or of fitness for a particular purpose.
 * See the GPLv2 for more details.
 *
 * Contributor:  A. M. Jehad Sarkar  <amjehad.sarkar@route1.com>
*/

package com.routeone.dc.vpn;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

public class DcContainerResponseReceiver extends BroadcastReceiver {

    public static final  String ACTION_FORWARDED_RESPONSE = "forwarded.containerapp.RESPONSE";
    public static final  String ACTION_FORWARDED_ERROR    = "forwarded.containerapp.ERROR";

    private static final String TAG = DcContainerResponseReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive()");
        Bundle extras = intent.getExtras();
        if (intent.getAction().equals(DcContainerInterface.ACTION_ERROR)) {
            LocalBroadcastManager.getInstance(context)
                    .sendBroadcast(new Intent(ACTION_FORWARDED_ERROR).putExtras(extras));
        } else {
            LocalBroadcastManager.getInstance(context)
                    .sendBroadcast(new Intent(ACTION_FORWARDED_RESPONSE).putExtras(extras));
        }
    }
}