Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

# -*- coding: utf-8 -*- 

 

# Licensed under the MIT license 

# http://opensource.org/licenses/mit-license.php 

 

# Copyright 2010 Frank Scholz <dev@coherence-project.org> 

 

import coherence.extern.louie as louie 

from coherence import log 

from coherence.upnp.devices.wan_connection_device_client import \ 

    WANConnectionDeviceClient 

from coherence.upnp.services.clients.wan_common_interface_config_client import\ 

    WANCommonInterfaceConfigClient 

 

 

class WANDeviceClient(log.LogAble): 

    logCategory = 'wan_device_client' 

 

    def __init__(self, device): 

        log.LogAble.__init__(self) 

        self.device = device 

        self.device_type = self.device.get_friendly_device_type() 

        self.version = int(self.device.get_device_type_version()) 

        self.icons = device.icons 

 

        self.wan_connection_device = None 

        self.wan_common_interface_connection = None 

 

        self.embedded_device_detection_completed = False 

        self.service_detection_completed = False 

 

        louie.connect( 

            self.embedded_device_notified, 

            signal='Coherence.UPnP.EmbeddedDeviceClient.detection_completed', 

            sender=self.device) 

 

        try: 

            wan_connection_device = \ 

                self.device.get_embedded_device_by_type( 

                    'WANConnectionDevice')[0] 

            self.wan_connection_device = WANConnectionDeviceClient( 

                wan_connection_device) 

        except Exception as er: 

            self.warning( 

                "Embedded WANConnectionDevice device not available, " 

                "device not implemented properly according to " 

                "the UPnP specification [ERROR: {}]".format(er)) 

            raise 

 

        louie.connect(self.service_notified, 

                      signal='Coherence.UPnP.DeviceClient.Service.notified', 

                      sender=self.device) 

        for service in self.device.get_services(): 

            if service.get_type() in [ 

                    "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"]: 

                self.wan_common_interface_connection = \ 

                    WANCommonInterfaceConfigClient(service) 

 

        self.info("WANDevice %s", self.device.get_friendly_name()) 

 

    def remove(self): 

        self.info("removal of WANDeviceClient started") 

        if self.wan_common_interface_connection is not None: 

            self.wan_common_interface_connection.remove() 

        if self.wan_connection_device is not None: 

            self.wan_connection_device.remove() 

 

    def embedded_device_notified(self, device): 

        self.info("EmbeddedDevice %r sent notification", device) 

        if self.embedded_device_detection_completed: 

            return 

 

        self.embedded_device_detection_completed = True 

        if self.embedded_device_detection_completed is True and \ 

                self.service_detection_completed is True: 

            louie.send( 

                'Coherence.UPnP.EmbeddedDeviceClient.detection_completed', 

                None, 

                self) 

 

    def service_notified(self, service): 

        self.info("Service %r sent notification", service) 

        if self.service_detection_completed: 

            return 

        if self.wan_common_interface_connection is not None: 

            if not hasattr(self.wan_common_interface_connection.service, 

                           'last_time_updated'): 

                return 

            if self.wan_common_interface_connection.\ 

                    service.last_time_updated is None: 

                return 

        self.service_detection_completed = True 

        if self.embedded_device_detection_completed is True and \ 

                self.service_detection_completed is True: 

            louie.send( 

                'Coherence.UPnP.EmbeddedDeviceClient.detection_completed', 

                None, 

                self)