package SRevent

import (
	"errors"
	"netease_control_center/interfaces/log"
	"time"
)

func BroadCastSRevent(srtype SRevent_type) {
	if ev, ok := allevents[srtype]; ok == true {
		ev.Cond.L.Lock()
		defer ev.Cond.L.Unlock()
		ev.Cond.Broadcast()
	} else {
		log.Println(log.ErrorLog, "SRevent system, can not find the ev:", srtype)
	}
}

func WaitSRevent(revent_type SRevent_type, waittime time.Duration) (timeOut bool) {
	if ev, ok := allevents[revent_type]; ok {
		ev.Cond.L.Lock()
		defer ev.Cond.L.Unlock()
		return ev.Cond.WaitWithTimeout(waittime)
	} else {
		log.Println(log.ErrorLog, "SRevent system, can not find the ev:", revent_type)
	}

	return false
}

func GetSReventChan(revent_type SRevent_type) (<-chan struct{}, error) {
	if ev, ok := allevents[revent_type]; ok {
		return ev.Cond.NotifyChan(), nil
	} else {
		return nil, errors.New("Not found the chan")
	}
}
