Subversion Repositories HomeAutomation

Rev

Rev 856 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
856 migan 1
############################################################################
2
#    Copyright (C) 2008 by Mattias Runge   #
3
#    mattias@runge.se   #
4
#                                                                          #
5
#    This program is free software; you can redistribute it and#or modify  #
6
#    it under the terms of the GNU General Public License as published by  #
7
#    the Free Software Foundation; either version 2 of the License, or     #
8
#    (at your option) any later version.                                   #
9
#                                                                          #
10
#    This program is distributed in the hope that it will be useful,       #
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
13
#    GNU General Public License for more details.                          #
14
#                                                                          #
15
#    You should have received a copy of the GNU General Public License     #
16
#    along with this program; if not, write to the                         #
17
#    Free Software Foundation, Inc.,                                       #
18
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
19
############################################################################
20
 
857 migan 21
class ServiceBase:
856 migan 22
    Id = 0
23
    Type = ''
24
    Online = False
25
    events = {}
26
    timers = {}
27
    timerArgs = {}
28
 
29
    def __init__(self, id, type):
30
        self.Id = id
31
        self.Type = type
32
 
33
    #def CreateInterval(self, interval, name, callback, args):
34
    #   self.timersArgs[name] = args
35
    #   self.timers[name] = threading.Timer(interval, callback, args)
36
    #   self.timers[name].start()
37
 
38
 
39
    def SetOnline(self):
40
        if not self.Online:
41
            print self.Type + " Service - " + str(self.Id) + ": Online"
42
            self.Online = True
43
            return True
44
        return False
45
 
46
    def SetOffline(self):
47
        if self.Online:
48
            print self.Type + " Service - " + str(self.Id) + ": Offline"
49
            self.Online = False
50
            return True
51
        return False
52
 
53
    #def RegisterIntervalHandler(self, event, interval, args, callback)
54
    #   self.serviceImap.RegisterIntervalHandler("onNewMail", 10, ["runge.se", "mattias@runge.se", "getur82", "Inbox"], self.onCheckImapHandler)
55
 
56
    def RegisterEventHandler(self, event, callback):
57
        self.events[event].append(callback)
58
 
59
    def CallEvent(self, event, data):
60
        for func in self.events[event]:
61
            func(data)
62
 
63
    def Log(self, text):
64
        print self.Type + " Service - " + str(self.Id) + ": " + text