예제 #1
0
    def GetAboutData(self):
        proxyBusObject = ProxyBusObject.ProxyBusObject(self.bus, SERVICE_NAME, "/About", self.session_id)
        iface = self.bus.GetInterface("org.alljoyn.About")
        proxyBusObject.AddInterface(iface)

        #     <method name="GetAboutData">
        #       <arg name="languageTag" type="s" direction="in"/>
        #       <arg name="aboutData" type="a{sv}" direction="out"/>
        #     </method>

        languageTag = MsgArg.MsgArg()
        languageTag.SetString("en")
        replyMsg = Message.Message(g_bus)
        proxyBusObject.MethodCall('org.alljoyn.About', "GetAboutData", languageTag, 1, replyMsg, 25000, 0)
        arg = replyMsg.GetArg(0)

        # Todo Tidy up MsgArg code. Could there be a way to dynamically create types based on the dbus signature ?
        num = C.c_uint()
        entries = MsgArg.MsgArg()
        arg.Get("a{sv}", [C.POINTER(C.c_uint), C.POINTER(MsgArg.MsgArgHandle)], [C.byref(num), C.byref(entries.handle)])
       
        for i in range(num.value):
            key = C.c_char_p()
            value_string = C.c_char_p()
            element = entries.ArrayElement(i)
            
            try:
                element.Get("{ss}", [C.POINTER(C.c_char_p), C.POINTER(C.c_char_p)], [C.byref(key), C.byref(value_string)])
                self.device_details[key.value] = value_string.value
            except QStatusException as ex:
                pass
예제 #2
0
 def CallGetCurrentItemUrl(self):
     proxyBusObject = ProxyBusObject.ProxyBusObject(self.bus, SERVICE_NAME, SERVICE_PATH, self.session_id)
     iface = self.bus.GetInterface("net.allplay.MCU")
     proxyBusObject.AddInterface(iface)
     replyMsg = Message.Message(g_bus)
     proxyBusObject.MethodCall('net.allplay.MCU', "GetCurrentItemUrl", None, 0, replyMsg, 25000, 0)
     return replyMsg.GetArg(0).GetString()
예제 #3
0
class MyAboutListener(AboutListener.AboutListener):
    def __init__(self, bus_attachment, context=None):
        super(MyAboutListener, self).__init__(context=context)
        self.bus = bus_attachment
        self.sessionListener = MySessionListener()

   

    def OnAboutListenerCallBack(self, context, busName, version, port, objectDescriptionArg, aboutDataArg):

        global s_interrupt

        objectDescription = AboutObjectDescription.AboutObjectDescription(objectDescriptionArg)

        print objectDescription.GetPaths()

        aboutData = AboutData.AboutData(aboutDataArg, language="en")

        print {f:aboutData.GetField(f).GetSingleCompleteValue() for f in aboutData.GetFields()}

        #self.printAboutData(aboutData, None, 2)

        print "*********************************************************************************"

        opts = Session.SessionOpts(Session.ALLJOYN_TRAFFIC_TYPE_MESSAGES,
                                   False,
                                   Session.ALLJOYN_PROXIMITY_ANY,
                                   TransportMask.ALLJOYN_TRANSPORT_ANY)

        self.bus.EnableConcurrentCallBacks()
        sessionId = self.bus.JoinSession(busName, port, self.sessionListener, opts)

        aboutProxy = AboutProxy.AboutProxy(self.bus, busName, sessionId)

        objArg = aboutProxy.GetObjectDescription()

        aboutObjectDescription = AboutObjectDescription.AboutObjectDescription(objArg)

        for path in aboutObjectDescription.GetPaths():
            print "\t", path
            for interface in aboutObjectDescription.GetInterfaces(path):
                print "\t\t", interface

        proxyBusObject = ProxyBusObject.ProxyBusObject(self.bus, busName, '/net/allplay/MediaPlayer', sessionId)
           
        try:
            proxyBusObject.IntrospectRemoteObject()
        except QStatusException, ex:
            print "Failed to introspect remote object."
                

        replyMsg = Message.Message(self.bus)
        proxyBusObject.MethodCall('net.allplay.MCU', "GetCurrentItemUrl", None, 0, replyMsg, 25000, 0)
        print "GetCurrentItemUrl:", replyMsg.GetArg(0).GetString()
예제 #4
0
    def CreateZone(self, device_ids):
        #     <method name="CreateZone">
        #       <arg name="slaves" type="as" direction="in"/>
        #       <arg name="zoneId" type="s" direction="out"/>
        #       <arg name="timestamp" type="i" direction="out"/>
        #       <arg name="slaves" type="a{si}" direction="out"/>
        #     </method>

        # We must remove the dice id that this player is as the speaker does
        # not accept it.
        self.device_ids = [d for d in device_ids if d != self.device_id]

        print "%s CreateZone: %s" % (str(self.device_id), str(self.device_ids))

        self.arg = MsgArg.MsgArg()
        size = len(self.device_ids)

        self.array = (C.c_char_p * size)()
        self.array[:] = self.device_ids
        self.arg.Set("as", [C.c_int, C.POINTER(C.c_char_p)],
                     [size, self.array])

        replyMsg = Message.Message(self.bus)
        try:
            self.proxyBusObject.MethodCall('net.allplay.ZoneManager',
                                           "CreateZone", self.arg, 1, replyMsg,
                                           100000, 0)

            print "zoneId:", replyMsg.GetArg(0).GetString()
            print "timestamp:", replyMsg.GetArg(1).GetInt32()

            # callback = MessageReceiver.MessageReceiverReplyHandlerFuncType(AllPlayer.OnReplyMessageCallback)
            # proxyBusObject.MethodCallAsync('net.allplay.ZoneManager', "CreateZone", callback, self.arg, 1, None, 55000, 0)

        except QStatusException as ex:
            print replyMsg
            raise
    def CreateZone(self, device_ids):
        # We must remove the id that this player is as the speaker does
        # not accept it.
        self.device_ids = [d for d in device_ids if d != self.device_id]

        self.arg = MsgArg.MsgArg()
        size = len(self.device_ids)

        self.array = (C.c_char_p * size)()

        print "CreateZone", self.device_ids

        self.array[:] = self.device_ids
        self.arg.Set(
            "as", [C.c_int, C.POINTER(C.c_char_p)], [size, self.array])

        replyMsg = Message.Message(self.bus)
        try:
            self.proxyBusObject.MethodCall(
                'net.allplay.ZoneManager', "CreateZone", self.arg, 1, replyMsg, 100000, 0)

        except QStatusException:
            print replyMsg
            raise
예제 #6
0
 def CallGetCurrentItemUrl(self):
     replyMsg = Message.Message(g_bus)
     self.proxyBusObject.MethodCall('net.allplay.MCU', "GetCurrentItemUrl",
                                    None, 0, replyMsg, 25000, 0)
     return replyMsg.GetArg(0).GetString()
예제 #7
0
    def OnAboutListenerCallBack(self, context, busName, version, port,
                                objectDescriptionArg, aboutDataArg):

        print "BusName", busName

        print "objectDescriptionArg", objectDescriptionArg, type(
            objectDescriptionArg)
        print "aboutDataArg", aboutDataArg, type(aboutDataArg)

        objectDescription = AboutObjectDescription.AboutObjectDescription(
            objectDescriptionArg)

        print "*********************************************************************************"
        print "Announce signal discovered"
        print "\tFrom bus", busName
        print "\tAbout version", version
        print "\tSessionPort", port
        print "\tObjectDescription:"
        print "*********************************************************************************"
        print "Announce signal discovered"

        for path in objectDescription.GetPaths():
            print "\t\t", path
            for interface in objectDescription.GetInterfaces(path):
                print "\t\t\t", interface

        print "\tAboutData:"
        aboutData = AboutData.AboutData(aboutDataArg, language="en")

        self.printAboutData(aboutData, None, 2)

        print "*********************************************************************************"

        opts = Session.SessionOpts(Session.ALLJOYN_TRAFFIC_TYPE_MESSAGES,
                                   False, Session.ALLJOYN_PROXIMITY_ANY,
                                   TransportMask.ALLJOYN_TRANSPORT_ANY)

        self.bus_attachment.EnableConcurrentCallBacks()

        print "JoiningSession", "busName", busName, "port", port, "opts", opts
        sessionId = self.bus_attachment.JoinSession(busName, port,
                                                    self.sessionListener, opts)
        print "SessionJoined sessionId = ", sessionId

        aboutProxy = AboutProxy.AboutProxy(self.bus_attachment, busName,
                                           sessionId)

        objArg = aboutProxy.GetObjectDescription()
        print "*********************************************************************************"
        print "AboutProxy.GetObjectDescription:"

        aboutObjectDescription = AboutObjectDescription.AboutObjectDescription(
            objArg)

        for path in aboutObjectDescription.GetPaths():
            print "\t", path
            for interface in aboutObjectDescription.GetInterfaces(path):
                print "\t\t", interface

        aArg = aboutProxy.GetAboutData()
        print "*********************************************************************************"
        print "AboutProxy.GetAboutData: (Default Language)"

        defaultLangAboutData = AboutData.AboutData()
        self.printAboutData(defaultLangAboutData, None, 1)

        defaultLanguage = defaultLangAboutData.GetDefaultLanguage()
        # Print out the AboutData for every language but the default it has already been printed.

        for lang in defaultLangAboutData.GetSupportedLanguages():
            if lang != defaultLanguage:
                aArg = aboutProxy.GetAboutData(language=lang)
                printAboutData(aArg, lang, 1)
            ver = aboutProxy.GetVersion()
            print "*********************************************************************************"
            print "AboutProxy.GetVersion %hd" % (ver, )
            print "*********************************************************************************"
            path = objectDescription.GetInterfacePaths(INTERFACE_NAME)[0]
            print "Calling %s/%s" % (path, INTERFACE_NAME)
            print "busName", busName, type(busName)
            print "path", path, type(path)
            print "sessionId", sessionId, type(sessionId)
            proxyBusObject = ProxyBusObject.ProxyBusObject(
                g_bus, busName, path, sessionId)

            print "proxyBusObject", proxyBusObject
            try:
                proxyBusObject.IntrospectRemoteObject()
            except QStatusException, ex:
                print "Failed to introspect remote object."

            arg = MsgArg.MsgArg()
            arg.SetString("ECHO Echo echo...")

            replyMsg = Message.Message(self.bus_attachment)

            proxyBusObject.MethodCall(INTERFACE_NAME, "Echo", arg, 1, replyMsg,
                                      25000, 0)

            print "Echo method reply:", replyMsg.GetArg(0).GetString()
    def GetPlaylist(self):
        """
        <method name="GetPlaylist">
        <arg name="items" type="a(ssssxsssa{ss}a{sv}v)" direction="out"/>
        <!-- see UpdatePlaylist -->
        <arg name="controllerType" type="s" direction="out"/>
        <arg name="playlistUserData" type="s" direction="out"/>
        </method>
        """
        replyMsg = Message.Message(self.bus)

        try:
            self.proxyBusObject.MethodCall(
                'net.allplay.MediaPlayer', "GetPlaylist", None, 0, replyMsg, 25000, 0)
        except QStatusException:
            return []

        arg = replyMsg.GetArg(0)

        num = C.c_size_t()
        entries = MsgArg.MsgArg()
        arg.Get("a(ssssxsssa{ss}a{sv}v)", [C.POINTER(C.c_size_t), C.POINTER(MsgArgHandle)], [
            C.byref(num), C.byref(entries.handle)])

        items = []

        for i in range(num.value):
            url = C.c_char_p()
            title = C.c_char_p()
            artist = C.c_char_p()
            thumbnail_url = C.c_char_p()
            duration = C.c_int64()
            mediaType = C.c_char_p()
            album = C.c_char_p()
            genre = C.c_char_p()

            #  a{ss}: other data
            other_data_num = C.c_size_t()
            other_data = MsgArg.MsgArg()

            # a{sv}: medium description (codec, container, protocol,
            medium_data_num = C.c_size_t()
            medium_data = MsgArg.MsgArg()

            user_data = MsgArg.MsgArg()

            element = entries.ArrayElement(i)

            try:
                # (ssssxsssa{ss}a{sv}v)
                element.Get(
                    "(ssssxsssa{ss}a{sv}v)", [C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_int64),
                                              C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_char_p),
                                              C.POINTER(C.c_size_t),
                                              C.POINTER(MsgArgHandle),
                                              C.POINTER(C.c_size_t),
                                              C.POINTER(MsgArgHandle),
                                              C.POINTER(MsgArgHandle)],
                    [C.byref(url),
                     C.byref(title),
                     C.byref(artist),
                     C.byref(thumbnail_url),
                     C.byref(duration),
                     C.byref(mediaType),
                     C.byref(album),
                     C.byref(genre),
                     C.byref(other_data_num),
                     C.byref(other_data.handle),
                     C.byref(medium_data_num),
                     C.byref(medium_data.handle),
                     C.byref(user_data.handle)])

                items.append({'url': url.value,
                                        'title': title.value,
                                        'artist': artist.value,
                                        'thumbnail_url': thumbnail_url.value,
                                        'duration': duration.value,
                                        'media_type': mediaType.value,
                                        'album': album.value,
                                        'genre': genre.value})

            except QStatusException, ex:
                print ex