Add mainloop state checking routines to ServiceBase