package com.tencent.gme.audio.apiexample;

import android.content.Intent;

import com.gme.TMG.ITMGContext;
import com.gme.TMG.ITMGType;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TMGCallbackDispatcher extends ITMGContext.ITMGDelegate{
    private static TMGCallbackDispatcher mInstance = null;
    private Set<TMGDispatcherBase> mSubDispatcherSet;

    private TMGCallbackDispatcher()
    {
        mSubDispatcherSet = new HashSet<>();
    }
    public static TMGCallbackDispatcher getInstance()
    {
        if (mInstance == null)
        {
            synchronized (TMGCallbackDispatcher.class)
            {
                if (mInstance == null)
                {
                    mInstance = new TMGCallbackDispatcher();
                }
            }
        }
        return mInstance;
    }

    public void OnEvent(ITMGType.ITMG_MAIN_EVENT_TYPE type, Intent data) {
        for (TMGDispatcherBase subDispatcher: mSubDispatcherSet) {
            subDispatcher.OnEvent(type, data);
        }
    }

    public void registerSubDispatcher(TMGDispatcherBase subDispatcher)
    {
        mSubDispatcherSet.add(subDispatcher);
    }

    public void unregisterSubDispatcher(TMGDispatcherBase subDispatcher)
    {
        mSubDispatcherSet.remove(subDispatcher);
    }
}
