def launch_route_calculation(route): global g_current_route global g_route_handle global g_routing_interface global g_navigationcore_session_handle global g_locations global start global destination g_current_route = route #get route handle ret = g_routing_interface.CreateRoute(dbus.UInt32(g_navigationcore_session_handle)) g_route_handle=ret[1] print ('Route handle: ' + str(g_route_handle)) print ('Calculating route from \ '+start+'(' + str(g_locations["start"][0]) + ',' + str(g_locations["start"][1]) + ') to \ '+destination+'(' + str(g_locations["destination"][0]) + ',' + str(g_locations["destination"][1]) + ')' ) #set waypoints waypointDoubleCapiType = 0x03 g_routing_interface.SetWaypoints(dbus.UInt32(g_navigationcore_session_handle), \ dbus.UInt32(g_route_handle), \ dbus.Boolean(0), \ dbus.Array([ \ dbus.Dictionary({dbus.Int32(genivi.LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(g_locations["start"][0])]),dbus.Int32(genivi.LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(g_locations["start"][1])])}), \ dbus.Dictionary({dbus.Int32(genivi.LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(g_locations["destination"][0])]),dbus.Int32(genivi.LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(g_locations["destination"][1])])}) \ ]) \ ) #calculate route g_routing_interface.CalculateRoute(dbus.UInt32(g_navigationcore_session_handle),dbus.UInt32(g_route_handle))
def routing_routeCalculationSuccessful_handler(routeHandle,unfullfilledPreferences): global g_guidance_active print ('Route Calculation Successfull: ' + str(routeHandle)) #get route overview overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(genivi.TOTAL_DISTANCE),dbus.Int32(genivi.TOTAL_TIME)])) #retrieve distance totalDistance = dbus.Struct(overview[dbus.Int32(genivi.TOTAL_DISTANCE)]) print ('Total Distance: ' + str(totalDistance[1]/1000) + ' km') totalTime = dbus.Struct(overview[dbus.Int32(genivi.TOTAL_TIME)]) m, s = divmod(totalTime[1], 60) h, m = divmod(m, 60) print ("Total Time: %d:%02d:%02d" % (h, m, s)) #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) valuesToReturn = [dbus.Int32(genivi.ROAD_NAME), dbus.Int32(genivi.START_LATITUDE), dbus.Int32(genivi.END_LATITUDE), dbus.Int32(genivi.START_LONGITUDE), dbus.Int32(genivi.END_LONGITUDE), dbus.Int32(genivi.DISTANCE), dbus.Int32(genivi.TIME), dbus.Int32(genivi.SPEED)] numberOfSegments = NUMBER_OF_SEGMENTS detailLevel = 0 offset = 0 ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(detailLevel),dbus.Array(valuesToReturn),dbus.UInt32(numberOfSegments),dbus.UInt32(offset)) print ("Total number of segments: " + str(ret[0]) ) #len(ret[1]) is size #ret[1][0][genivi.START_LATITUDE] is the start latitude g_guidance_active = True # pdb.set_trace() launch_guidance(routeHandle)
def translator(c, pack): """A translator for L{Change}s""" if pack: if isinstance(c.edit, Insertion): return dbus.Struct( (dbus.Int64(c.unique_id), dbus.Int64(c.parent), dbus.Int16(0), dbus.Int64(c.edit.position), dbus.UTF8String(c.edit.text)), signature='xxnxs') elif isinstance(c.edit, Deletion): return dbus.Struct( (dbus.Int64(c.unique_id), dbus.Int64(c.parent), dbus.Int16(1), dbus.Int64(c.edit.position), dbus.Int64(c.edit.length)), signature='xxnxx') elif isinstance(c.edit, Removal): return dbus.Struct( (dbus.Int64(c.unique_id), dbus.Int64(c.parent), dbus.Int16(2), dbus.Int64(c.edit.position), dbus.Int64(c.edit.length)), signature='xxnxx') else: raise Unimplemented else: if c[2] == 0: ed = Insertion(int(c[3]), str(c[4])) elif c[2] == 1: ed = Deletion(int(c[3]), int(c[4])) elif c[2] == 2: ed = Removal(int(c[3]), int(c[4])) else: raise "unknown type" return Change(int(c[0]), int(c[1]), ed)
def __init__(self, am, path, display_name, parameters): Object.__init__(self, am.connection, path) self._am = am self._connection = dbus.ObjectPath('/') self._connection_status = Connection_Status_Disconnected self._connection_status_reason = Connection_Status_Reason_None_Specified self._connection_error = u'' self._connection_error_details = dbus.Dictionary({}, signature='sv') self._service = u'' self._display_name = display_name self._icon = u'bob.png' self._enabled = True self._nickname = u'Bob' self._parameters = parameters self._has_been_online = False self._connect_automatically = False self._normalized_name = u'bob' self._automatic_presence = dbus.Struct( (Connection_Presence_Type_Available, 'available', ''), signature='uss') self._current_presence = dbus.Struct( (Connection_Presence_Type_Offline, 'offline', ''), signature='uss') self._requested_presence = dbus.Struct( (Connection_Presence_Type_Offline, 'offline', ''), signature='uss') self._avatar = dbus.Struct((dbus.ByteArray(''), 'image/png'), signature='ays') self._interfaces = [ ACCOUNT_IFACE_AVATAR_IFACE, ]
def catchall_route_calculation_signals_handler(routeHandle, status, percentage): print 'Route Calculation: ' + str(int(percentage)) + ' %' if int(percentage) == 100: #get route overview overview = g_routing_interface.GetRouteOverview(dbus.UInt32(g_route_handle),dbus.Array([dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE),dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)])) #retrieve distance totalDistance = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_DISTANCE)]) print 'Total Distance: ' + str(totalDistance[1]/1000) + ' km' totalTime = dbus.Struct(overview[dbus.Int32(GENIVI_NAVIGATIONCORE_TOTAL_TIME)]) m, s = divmod(totalTime[1], 60) h, m = divmod(m, 60) print "Total Time: %d:%02d:%02d" % (h, m, s) #get route segments GetRouteSegments(const uint32_t& routeHandle, const int16_t& detailLevel, const std::vector< DBusCommonAPIEnumeration >& valuesToReturn, const uint32_t& numberOfSegments, const uint32_t& offset, uint32_t& totalNumberOfSegments, std::vector< std::map< DBusCommonAPIEnumeration, DBusCommonAPIVariant > >& routeSegments) valuesToReturn = [dbus.Int32(GENIVI_NAVIGATIONCORE_ROAD_NAME), dbus.Int32(GENIVI_NAVIGATIONCORE_START_LATITUDE), dbus.Int32(GENIVI_NAVIGATIONCORE_END_LATITUDE), dbus.Int32(GENIVI_NAVIGATIONCORE_START_LONGITUDE), dbus.Int32(GENIVI_NAVIGATIONCORE_END_LONGITUDE), dbus.Int32(GENIVI_NAVIGATIONCORE_DISTANCE), dbus.Int32(GENIVI_NAVIGATIONCORE_TIME), dbus.Int32(GENIVI_NAVIGATIONCORE_SPEED)] ret = g_routing_interface.GetRouteSegments(dbus.UInt32(g_route_handle),dbus.Int16(0),dbus.Array(valuesToReturn),dbus.UInt32(500),dbus.UInt32(0)) print "Total number of segments: " + str(ret[0]) #len(ret[1]) is size #ret[1][0][GENIVI_NAVIGATIONCORE_START_LATITUDE] is the start latitude # pdb.set_trace() route = g_current_route + 1 if route < routes.length: launch_route_calculation(route) else: for i in range(routes.length): g_routing_interface.DeleteRoute(dbus.UInt32(g_session_handle),dbus.UInt32(routes[i].getElementsByTagName("handle")[0].childNodes[0].data)) g_session_interface.DeleteSession(dbus.UInt32(g_session_handle))
def dict_to_dbus_properties(ct): props = [] for (key, value) in ct: if isinstance(value, int): props.append(dbus.Struct((key, dbus.UInt64(value)))) else: props.append(dbus.Struct((key, dbus.String(value)))) return dbus.Array(props)
def getDbus(): global step global host # manage the logreplayer depending on the step if step == Step.START: launch("start.log", host) elif step == Step.INITIALIZATION: launch("initialization.log", host) elif step == Step.HIGH_TANK_LEVEL: launch("high-tank-level.log", host) elif step == Step.LOW_TANK_LEVEL: launch("low-tank-level.log", host) elif step == Step.END: displayStatus('End simulation ') loop.quit() else: displayStatus('error') pygame.quit() loop.quit() # get the values on amb engineSpeed = ambEngineSpeedInterface.GetSpeed() displayEngineSpeed(str(int(engineSpeed[0]))) fuelLevel = ambFuelInterface.GetLevel() displayFuelLevel(str(int(fuelLevel[0]))) fuelInstCons = ambFuelInterface.GetInstantConsumption() displayFuelInstant("{:.2f}".format(int(fuelInstCons[0]) * FUEL_CONVERSION)) odometer = ambOdometerInterface.GetOdometer() displayVehicleSpeed(str(int(odometer[0]) * SPEED_CONVERSION)) # get the tank distance instantData = fuelStopAdvisorInterface.getInstantData() if dbus.Int32(Genivi.FUELSTOPADVISOR_TANK_DISTANCE) in instantData: tankDistance = dbus.Struct(instantData[dbus.Int32( Genivi.FUELSTOPADVISOR_TANK_DISTANCE)]) displayFuelStopAdvisorTankDistance(str(int(tankDistance[1])) + ' ') else: displayFuelStopAdvisorTankDistance("-----") if dbus.Int32( Genivi.FUELSTOPADVISOR_ENHANCED_TANK_DISTANCE) in instantData: enhancedTankDistance = dbus.Struct(instantData[dbus.Int32( Genivi.FUELSTOPADVISOR_ENHANCED_TANK_DISTANCE)]) displayFuelStopAdvisorEnhancedTankDistance( str(int(enhancedTankDistance[1])) + ' ') else: displayFuelStopAdvisorEnhancedTankDistance('-----') displayStep(str(step.name)) # refresh screen refresh() return True
def __init__(self, obj, addr): self.addr = addr self.agent = None if (self.addr == 'net.connman.Manager'): self._props = dbus.Dictionary({dbus.String(u'State'): dbus.String(u'online', variant_level=1), dbus.String(u'OfflineMode'): dbus.Boolean(False, variant_level=1), dbus.String(u'SessionMode'): dbus.Boolean(False, variant_level=1)}, signature=dbus.Signature('sv')) # noqa self._technologies = dbus.Array([dbus.Struct((dbus.ObjectPath('/net/connman/technology/wifi'), dbus.Dictionary({dbus.String(u'Connected'): dbus.Boolean(False, variant_level=1), dbus.String(u'Tethering'): dbus.Boolean(False, variant_level=1), dbus.String(u'Type'): dbus.String(u'wifi', variant_level=1), dbus.String(u'Name'): dbus.String(u'WiFi', variant_level=1), dbus.String(u'Powered'): dbus.Boolean(True, variant_level=1)}, signature=dbus.Signature('sv'))), signature=None), dbus.Struct((dbus.ObjectPath('/net/connman/technology/ethernet'), dbus.Dictionary({dbus.String(u'Connected'): dbus.Boolean(True, variant_level=1), dbus.String(u'Tethering'): dbus.Boolean(False, variant_level=1), dbus.String(u'Type'): dbus.String(u'ethernet', variant_level=1), dbus.String(u'Name'): dbus.String(u'Wired', variant_level=1), dbus.String(u'Powered'): dbus.Boolean(True, variant_level=1)}, signature=dbus.Signature('sv'))), signature=None)], signature=dbus.Signature('(oa{sv})')) # noqa self._services = dbus.Array([dbus.Struct((dbus.ObjectPath('/net/connman/service/ethernet_b827ebaf24d8_cable'), dbus.Dictionary({dbus.String(u'IPv6.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Privacy'): dbus.String(u'disabled', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'AutoConnect'): dbus.Boolean(True, variant_level=1), dbus.String(u'Name'): dbus.String(u'Wired', variant_level=1), dbus.String(u'Nameservers'): dbus.Array([dbus.String(u'192.168.1.254')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Favorite'): dbus.Boolean(True, variant_level=1), dbus.String(u'Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'State'): dbus.String(u'online', variant_level=1), dbus.String(u'Proxy'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'direct', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv4'): dbus.Dictionary({dbus.String(u'Netmask'): dbus.String(u'255.255.255.0', variant_level=1), dbus.String(u'Gateway'): dbus.String(u'192.168.1.254', variant_level=1), dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1), dbus.String(u'Address'): dbus.String(u'192.168.1.79', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Timeservers'): dbus.Array([dbus.String(u'192.168.1.254')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv6'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Domains'): dbus.Array([dbus.String(u'home')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Ethernet'): dbus.Dictionary({dbus.String(u'Interface'): dbus.String(u'eth0', variant_level=1), dbus.String(u'MTU'): dbus.UInt16(1500, variant_level=1), dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Address'): dbus.String(u'B8:27:EB:AF:24:D8', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Security'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Proxy.Configuration'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Type'): dbus.String(u'ethernet', variant_level=1), dbus.String(u'Immutable'): dbus.Boolean(False, variant_level=1), dbus.String(u'IPv4.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None), dbus.Struct((dbus.ObjectPath('/net/connman/service/wifi_000f1330203f_4254576946692d776974682d464f4e_managed_none'), dbus.Dictionary({dbus.String(u'Strength'): dbus.Byte(73, variant_level=1), dbus.String(u'Nameservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'State'): dbus.String(u'idle', variant_level=1), dbus.String(u'Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Type'): dbus.String(u'wifi', variant_level=1), dbus.String(u'Security'): dbus.Array([dbus.String(u'none')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'AutoConnect'): dbus.Boolean(False, variant_level=1), dbus.String(u'Immutable'): dbus.Boolean(False, variant_level=1), dbus.String(u'Proxy'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv4.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv6.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Privacy'): dbus.String(u'disabled', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Name'): dbus.String(u'BTWiFi-with-FON', variant_level=1), dbus.String(u'Favorite'): dbus.Boolean(False, variant_level=1), dbus.String(u'Timeservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Domains'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Ethernet'): dbus.Dictionary({dbus.String(u'Interface'): dbus.String(u'wlan0', variant_level=1), dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Address'): dbus.String(u'00:0F:13:30:20:3F', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Proxy.Configuration'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv4'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv6'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None), dbus.Struct((dbus.ObjectPath('/net/connman/service/wifi_000f1330203f_4254487562352d4e473657_managed_psk'), dbus.Dictionary({dbus.String(u'Strength'): dbus.Byte(73, variant_level=1), dbus.String(u'Nameservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'State'): dbus.String(u'idle', variant_level=1), dbus.String(u'Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Type'): dbus.String(u'wifi', variant_level=1), dbus.String(u'Security'): dbus.Array([dbus.String(u'psk'), dbus.String(u'wps')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'AutoConnect'): dbus.Boolean(False, variant_level=1), dbus.String(u'Immutable'): dbus.Boolean(False, variant_level=1), dbus.String(u'Proxy'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv4.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv6.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Privacy'): dbus.String(u'disabled', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Name'): dbus.String(u'BTHub5-NG6W', variant_level=1), dbus.String(u'Favorite'): dbus.Boolean(False, variant_level=1), dbus.String(u'Timeservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Domains'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Ethernet'): dbus.Dictionary({dbus.String(u'Interface'): dbus.String(u'wlan0', variant_level=1), dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Address'): dbus.String(u'00:0F:13:30:20:3F', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Proxy.Configuration'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv4'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv6'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None), dbus.Struct((dbus.ObjectPath('/net/connman/service/wifi_000f1330203f_544e434150374345434535_managed_psk'), dbus.Dictionary({dbus.String(u'Strength'): dbus.Byte(49, variant_level=1), dbus.String(u'Nameservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'State'): dbus.String(u'idle', variant_level=1), dbus.String(u'Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Type'): dbus.String(u'wifi', variant_level=1), dbus.String(u'Security'): dbus.Array([dbus.String(u'psk'), dbus.String(u'wps')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'AutoConnect'): dbus.Boolean(False, variant_level=1), dbus.String(u'Immutable'): dbus.Boolean(False, variant_level=1), dbus.String(u'Proxy'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv4.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv6.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Privacy'): dbus.String(u'disabled', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Name'): dbus.String(u'TNCAP7CECE5', variant_level=1), dbus.String(u'Favorite'): dbus.Boolean(False, variant_level=1), dbus.String(u'Timeservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Domains'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Ethernet'): dbus.Dictionary({dbus.String(u'Interface'): dbus.String(u'wlan0', variant_level=1), dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Address'): dbus.String(u'00:0F:13:30:20:3F', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Proxy.Configuration'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv4'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'IPv6'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None)], signature=dbus.Signature('(oa{sv})')) # noqa elif (self.addr == 'net.connman.Technology'): self._props = dbus.Dictionary({dbus.String(u'Connected'): dbus.Boolean(False, variant_level=1), dbus.String(u'Tethering'): dbus.Boolean(False, variant_level=1), dbus.String(u'Type'): dbus.String(u'wifi', variant_level=1), dbus.String(u'Name'): dbus.String(u'WiFi', variant_level=1), dbus.String(u'Powered'): dbus.Boolean(True, variant_level=1)}, signature=dbus.Signature('sv')) # noqa elif (self.addr == 'net.connman.Service'): self._props = dbus.Dictionary({dbus.String(u'IPv6.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Privacy'): dbus.String(u'disabled', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'AutoConnect'): dbus.Boolean(True, variant_level=1), dbus.String(u'Name'): dbus.String(u'Wired', variant_level=1), dbus.String(u'Nameservers'): dbus.Array([dbus.String(u'192.168.1.254')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Favorite'): dbus.Boolean(True, variant_level=1), dbus.String(u'Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'State'): dbus.String(u'online', variant_level=1), dbus.String(u'Proxy'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'direct', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv4'): dbus.Dictionary({dbus.String(u'Netmask'): dbus.String(u'255.255.255.0', variant_level=1), dbus.String(u'Gateway'): dbus.String(u'192.168.1.254', variant_level=1), dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1), dbus.String(u'Address'): dbus.String(u'192.168.1.79', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Timeservers'): dbus.Array([dbus.String(u'192.168.1.254')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'IPv6'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Domains'): dbus.Array([dbus.String(u'home')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Ethernet'): dbus.Dictionary({dbus.String(u'Interface'): dbus.String(u'eth0', variant_level=1), dbus.String(u'MTU'): dbus.UInt16(1500, variant_level=1), dbus.String(u'Method'): dbus.String(u'auto', variant_level=1), dbus.String(u'Address'): dbus.String(u'B8:27:EB:AF:24:D8', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Security'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'Proxy.Configuration'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String(u'Type'): dbus.String(u'ethernet', variant_level=1), dbus.String(u'Immutable'): dbus.Boolean(False, variant_level=1), dbus.String(u'IPv4.Configuration'): dbus.Dictionary({dbus.String(u'Method'): dbus.String(u'dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv')) # noqa
def enhancedPositionPositionUpdateHandler(arg): # get the position enhancedPosition = enhancedPositionInterface.GetPositionInfo(arg) if (arg & Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE ) == Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE: latitude = dbus.Struct( enhancedPosition[1][Genivi.ENHANCEDPOSITIONSERVICE_LATITUDE]) displayLatitude("{:.3f}".format(float(latitude[1]))) if (arg & Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE ) == Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE: longitude = dbus.Struct( enhancedPosition[1][Genivi.ENHANCEDPOSITIONSERVICE_LONGITUDE]) displayLongitude("{:.3f}".format(float(longitude[1])))
def attr_struct(self, index, type_map, default='undisclosed'): try: if self.state.Attr[index] not in type_map: log_error("LV %s %s with lv_attr %s, lv_attr[%d] = " "'%s' is not known" % (self.Uuid, self.Name, self.Attr, index, self.state.Attr[index])) return dbus.Struct((self.state.Attr[index], type_map.get(self.state.Attr[index], default)), signature="(ss)") except BaseException: st = traceback.format_exc() log_error("attr_struct: \n%s" % st) return dbus.Struct(('?', 'Unavailable'), signature="(ss)")
def format_secret(session, secret, content_type): """Formats `secret` to make possible to pass it to the Secret Service API.""" if not isinstance(secret, bytes): secret = secret.encode('utf-8') if not session.encrypted: return dbus.Struct( (session.object_path, '', dbus.ByteArray(secret), content_type)) # PKCS-7 style padding padding = 0x10 - (len(secret) & 0xf) secret += bytes(bytearray((padding, )) * padding) aes_iv = os.urandom(0x10) aes = Cipher.AES.new(session.aes_key, Cipher.MODE_CBC, Cipher.AES.aes_iv) encrypted_secret = aes.encrypt(secret) return dbus.Struct((session.object_path, dbus.Array(aes_iv), dbus.Array(bytearray(encrypted_secret)), content_type))
def set(section, key, value): """Store a secret config value for a given section/key. Indicates if storage failed or succeeded. """ if not dbus: logger.debug( "Saving %s/%s to keyring failed. (dbus not installed)", section, key ) return False try: bus = dbus.SessionBus() except dbus.exceptions.DBusException as e: logger.debug("Saving %s/%s to keyring failed. (%s)", section, key, e) return False if not bus.name_has_owner("org.freedesktop.secrets"): logger.debug( "Saving %s/%s to keyring failed. " "(org.freedesktop.secrets service not running)", section, key, ) return False service = _service(bus) collection = _collection(bus) if not collection: return False if isinstance(value, str): value = value.encode() session = service.OpenSession("plain", EMPTY_STRING)[1] secret = dbus.Struct( (session, "", dbus.ByteArray(value), "plain/text; charset=utf8") ) label = f"mopidy: {section}/{key}" attributes = {"service": "mopidy", "section": section, "key": key} properties = { "org.freedesktop.Secret.Item.Label": label, "org.freedesktop.Secret.Item.Attributes": attributes, } try: item, prompt = collection.CreateItem(properties, secret, True) except dbus.exceptions.DBusException as e: # TODO: catch IsLocked errors etc. logger.debug("Saving %s/%s to keyring failed. (%s)", section, key, e) return False if prompt == "/": return True _prompt(bus, prompt).Dismiss() logger.debug( "Saving secret %s/%s failed. (Keyring is locked)", section, key ) return False
def encode_secret(self, secret, content_type): (params, data) = self.algorithm.encrypt(self.key, secret) # print " mock iv: ", hex_encode(params) # print " mock ciph: ", hex_encode(data) return dbus.Struct((dbus.ObjectPath(self.path), dbus.ByteArray(params), dbus.ByteArray(data), dbus.String(content_type)), signature="oayays")
def testResultTuple(self): """ Test result with tuple. """ result = _info_to_xformer( (("thing", (lambda x: _option_to_tuple(x, 0)), "(bt)"), )) self.assertEqual(result((None, )), [ dbus.Struct((dbus.Boolean(False), dbus.UInt64(0)), signature=dbus.Signature("bt")) ]) self.assertEqual(result((32, )), [ dbus.Struct((dbus.Boolean(True), dbus.UInt64(32)), signature=dbus.Signature("bt")) ])
def VolumeType(self): type_map = { 'C': 'Cache', 'm': 'mirrored', 'M': 'Mirrored without initial sync', 'o': 'origin', 'O': 'Origin with merging snapshot', 'r': 'raid', 'R': 'Raid without initial sync', 's': 'snapshot', 'S': 'merging Snapshot', 'p': 'pvmove', 'v': 'virtual', 'i': 'mirror or raid image', 'I': 'mirror or raid Image out-of-sync', 'l': 'mirror log device', 'c': 'under conversion', 'V': 'thin Volume', 't': 'thin pool', 'T': 'Thin pool data', 'e': 'raid or pool metadata or pool metadata spare', '-': 'Unspecified' } return dbus.Struct((self.state.Attr[0], type_map[self.state.Attr[0]]), signature="as")
def ip6route_native2net(self, ip6route_list): dest = self.ip6_native2net(ip6route_list[0]) prefix = dbus.UInt32(self.ip6_prefix_str2int(ip6route_list[1])) next_hop = self.ip6_native2net(ip6route_list[2]) metric = dbus.UInt32(ip6route_list[3]) return dbus.Struct((dest, prefix, next_hop, metric), signature=None)
def apply_signature(value, sig, utf8_strings=False): """Casts basic types to the right dbus types and packs them into containers with the right signature, so they get validated on sending.""" # dbus properties are variant, but have a signature defined, so # we have to convert manually here. if sig in TYPE_MAP: return TYPE_MAP[sig](value) elif sig.startswith("a{"): return dbus.Dictionary(value, signature=sig[2:-1]) elif sig.startswith("a("): return dbus.Struct(value, signature=sig[2:-1]) elif sig.startswith("a"): return dbus.Array(value, signature=sig[1:]) elif sig == "s": if utf8_strings and not PY3: if isinstance(value, text_type): value = value.encode("utf-8") return dbus.UTF8String(value) else: if isinstance(value, bytes): value = value.decode("utf-8") return dbus.String(value) else: return TYPE_MAP[sig](value) # Unknown type, just return as is return value
def createMapView(): global g_mapviewer_sessionhandle global g_mapviewer_sessionstatus global g_mapviewer_sessionlist global g_mapviewer_maphandle #get mapviewer session handle ret = g_mapviewer_session_interface.CreateSession(dbus.String('test mapviewer')) g_mapviewer_sessionhandle=ret[1] print ('Mapviewer session handle: ' + str(g_mapviewer_sessionhandle)) g_mapviewer_sessionstatus = g_mapviewer_session_interface.GetSessionStatus(dbus.UInt32(g_mapviewer_sessionhandle)); print ('Mapviewer session status: ' + str(g_mapviewer_sessionstatus)) g_mapviewer_sessionlist = g_mapviewer_session_interface.GetAllSessions(); print ('Mapviewer active sessions = ' + str(len(g_mapviewer_sessionlist))) #get mapviewer handle ret = g_mapviewercontrol_interface.CreateMapViewInstance( \ dbus.UInt32(g_mapviewer_sessionhandle), \ dbus.Struct((dbus.UInt16(HORIZONTAL_SIZE),dbus.UInt16(VERTICAL_SIZE))), \ dbus.Int32(genivi.MAIN_MAP)) g_mapviewer_maphandle=ret[1] print ('MapView handle: ' + str(g_mapviewer_maphandle)) time.sleep(2) print ('Stop following the car position') g_mapviewercontrol_interface.SetFollowCarMode( \ dbus.UInt32(g_mapviewer_sessionhandle), \ dbus.UInt32(g_mapviewer_maphandle), \ dbus.Boolean(False))
def _contacts_as_dbus_structure(self, contacts): ''' get info from list of Contact objects and create dbus dict ''' if not contacts: return None prim_contact = None # primary contact for contact in contacts: if prim_contact is None or contact.priority > prim_contact.priority: prim_contact = contact contact_dict = DBUS_DICT_SV() contact_dict['name'] = DBUS_STRING(prim_contact.name) contact_dict['show'] = DBUS_STRING(prim_contact.show) contact_dict['jid'] = DBUS_STRING(prim_contact.jid) if prim_contact.keyID: keyID = None if len(prim_contact.keyID) == 8: keyID = prim_contact.keyID elif len(prim_contact.keyID) == 16: keyID = prim_contact.keyID[8:] if keyID: contact_dict['openPGP'] = keyID contact_dict['resources'] = dbus.Array([], signature='(sis)') for contact in contacts: resource_props = dbus.Struct((DBUS_STRING(contact.resource), dbus.Int32(contact.priority), DBUS_STRING(contact.status))) contact_dict['resources'].append(resource_props) contact_dict['groups'] = dbus.Array([], signature='(s)') for group in prim_contact.groups: contact_dict['groups'].append((DBUS_STRING(group),)) return contact_dict
def GetPresences(self, Contacts): Presences = dbus.Dictionary(signature='u(uss)') handles = {} names = [] ts = time.time() for handle_id in Contacts: handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) handle.contact = self.get_contact_info(handle.name) if handle.contact.get('status_updated', 0) < (ts - 120): names.append(handle.name) handles[handle.name]=handle if names: statuses = self.Api.users.get(user_ids=names,fields=['online','status']) for info in statuses: uid = str(info.get('id')) if uid in handles.keys(): handles[uid].contact.update(info) handles[uid].contact['status_updated'] = ts for handle in handles.values(): if handle.contact.get('online'): status = [2,telepathy.CONNECTION_PRESENCE_STATUS_AVAILABLE,unicode(handle.contact.get('status',u''))] else: status = [1,telepathy.CONNECTION_PRESENCE_STATUS_OFFLINE,unicode(handle.contact.get('status',u''))] Presences[handle.id] = dbus.Struct(status,signature='uss') gobject.idle_add(self.PresencesChanged,Presences) return Presences
def setPresence(self, presence): if not helpers.isInstalled( 'telepathy-mission-control-5' ) or 'mission-control' not in commands.getoutput( 'ps -A | grep mission-control'): return account_manager = bus.get_object( 'org.freedesktop.Telepathy.AccountManager', '/org/freedesktop/Telepathy/AccountManager') accounts = account_manager.Get( 'org.freedesktop.Telepathy.AccountManager', 'ValidAccounts') for account_path in accounts: if str(account_path ) == '/org/freedesktop/Telepathy/Account/ring/tel/ring': continue account = bus.get_object( 'org.freedesktop.Telepathy.AccountManager', account_path) #account.Set('org.freedesktop.Telepathy.Account', 'Enabled', dbus.Struct((dbus.Boolean(True)), signature='b'), dbus_interface='org.freedesktop.DBus.Properties') enabled = account.Get('org.freedesktop.Telepathy.Account', 'Enabled') if not enabled: continue presence_text = "" if presence in STATUSLIST: presence_text = STATUSLIST[presence] account.Set('org.freedesktop.Telepathy.Account', 'RequestedPresence', \ dbus.Struct((dbus.UInt32(presence), presence_text, ''), signature='uss'), dbus_interface='org.freedesktop.DBus.Properties')
def serialize_object(o): if isinstance(o, Serializable): l = [o.__NAME__] o.serialize(l) return dbus.Struct(l) else: return o
def GetRequestChannels(self): ret = dbus.Array([], signature="(oa{sv})") channels = self.ListChannels() for channel in channels: props = self._generate_props(channel._type, channel._handle, True) ret.append( dbus.Struct([channel._object_path, props], signature="oa{sv}")) return ret
def format_secret(session, secret, content_type): """Formats `secret` to make possible to pass it to the Secret Service API.""" if not isinstance(secret, bytes): secret = secret.encode('utf-8') if not session.encrypted: return dbus.Struct( (session.object_path, '', dbus.ByteArray(secret), content_type)) # PKCS-7 style padding padding = 0x10 - (len(secret) & 0xf) secret += bytes(bytearray((padding, )) * padding) aes_iv = os.urandom(0x10) aes = algorithms.AES(session.aes_key) encryptor = Cipher(aes, modes.CBC(aes_iv), default_backend()).encryptor() encrypted_secret = encryptor.update(secret) + encryptor.finalize() return dbus.Struct((session.object_path, dbus.Array(aes_iv), dbus.Array(bytearray(encrypted_secret)), content_type))
def test_struct(self): from xpra.dbus.helper import dbus_to_native import dbus thestring = "foo" struct = dbus.Struct((dbus.String(thestring), ), signature=None) v = dbus_to_native(struct) assert v and isinstance(v, list) assert v[0] == thestring
def launch_route_calculation(route): global g_current_route global g_route_handle global g_routing_interface global g_navigationcore_session_handle g_current_route = route print('Route name: ' + routes[g_current_route].getElementsByTagName("name") [0].childNodes[0].data) #get route handle ret = g_routing_interface.CreateRoute( dbus.UInt32(g_navigationcore_session_handle)) g_route_handle = ret[1] routes[g_current_route].getElementsByTagName( "handle")[0].childNodes[0].data = g_route_handle print('Route handle: ' + str(g_route_handle)) start = routes[g_current_route].getElementsByTagName( "start")[0].childNodes[0].data dest = routes[g_current_route].getElementsByTagName( "destination")[0].childNodes[0].data print('Calculating route from \ ' + start + '(' + str(locations[routes[g_current_route].getElementsByTagName("start") [0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName("start") [0].childNodes[0].data][1]) + ') to \ ' + dest + '(' + str(locations[routes[g_current_route].getElementsByTagName( "destination")[0].childNodes[0].data][0]) + ',' + str(locations[routes[g_current_route].getElementsByTagName( "destination")[0].childNodes[0].data][1]) + ')') #set waypoints waypointDoubleCapiType = 0x03 g_routing_interface.SetWaypoints(dbus.UInt32(g_navigationcore_session_handle), \ dbus.UInt32(g_route_handle), \ dbus.Boolean(0), \ dbus.Array([ \ dbus.Dictionary({dbus.Int32(genivi.LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0])]),dbus.Int32(genivi.LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1])])}), \ dbus.Dictionary({dbus.Int32(genivi.LATITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][0])]),dbus.Int32(genivi.LONGITUDE):dbus.Struct([dbus.Byte(waypointDoubleCapiType),dbus.Double(locations[routes[g_current_route].getElementsByTagName("destination")[0].childNodes[0].data][1])])}) \ ]) \ ) #calculate route g_routing_interface.CalculateRoute( dbus.UInt32(g_navigationcore_session_handle), dbus.UInt32(g_route_handle))
def format_secret(session, secret, content_type): """Formats `secret` to make possible to pass it to the Secret Service API.""" if not isinstance(secret, bytes): secret = secret.encode('utf-8') if not session.encrypted: return dbus.Struct( (session.object_path, '', dbus.ByteArray(secret), content_type)) # PKCS-7 style padding padding = 0x10 - (len(secret) & 0xf) secret += bytes(bytearray((padding, )) * padding) aes_iv = long_to_bytes(getrandbits(0x80)) # If shorter than 16 bytes, prepend zero bytes aes_iv = b'\x00' * (0x10 - len(aes_iv)) + aes_iv aes_cipher = AESCipher(session.aes_key, mode=MODE_CBC, IV=aes_iv) return dbus.Struct( (session.object_path, dbus.Array(aes_iv), dbus.Array(bytearray(aes_cipher.encrypt(secret))), content_type))
def add_seat(self, properties, is_self): # find a new name count = 0 while True: id = 'seat%d' % count if id not in self.seats: break count += 1 path = dbus.ObjectPath(SEAT_PATH + id) seat_props = { 'Id': id, 'ActiveSession': properties.get( 'ActiveSession', dbus.Struct(('c2', '/org/freedesktop/login1/session/c2'), signature='so')), 'CanMultiSession': properties.get('CanMultiSession', True), 'CanTTY': properties.get('CanTTY', True), 'CanGraphical': properties.get('CanGraphical', True), 'Sessions': properties.get( 'Sessions', dbus.Array([('c2', '/org/freedesktop/login1/session/c2')], signature='(so)')), 'IdleHint': properties.get('IdleHint', False), 'IdleSinceHint': properties.get('IdleSinceHint', dbus.UInt64(1489590854604069)), 'IdleSinceHintMonotonic': properties.get('IdleSinceHintMonotonic', dbus.UInt64(18537117367)), } seat_methods = [ ('Terminate', '', '', ""), ('ActivateSession', 's', '', ""), ('SwitchTo', 'u', '', ""), ('SwitchToNext', '', '', ""), ('SwitchToPrevious', '', '', ""), ] self.seats[id] = self.AddObject(path, SEAT_IFACE, seat_props, seat_methods) if is_self: self_path = dbus.ObjectPath(SEAT_PATH + 'self') try: self.RemoveObject(self_path) except dbus.exceptions.DBusException: pass self.AddObject(self_path, SEAT_IFACE, seat_props, seat_methods) return path
def RequestContactInfo(self, Contact): info = dbus.Array(signature='(sasas)') handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, Contact) contact = self.get_contact_info(handle.name) fn = dbus.Struct(('fn',[],[u'{first_name} {last_name}'.format(**contact)]),signature='sasas') info.append(fn) if 'screen_name' not in contact.keys(): contact['screen_name']=u'id{}'.format(handle.name) url = dbus.Struct(('url', [], [u'http://vk.com/{screen_name}'.format(**contact)]),signature='sasas') info.append(url) if 'nickname' in contact.keys(): nickname = dbus.Struct(('nickname', [], [u'{nickname}'.format(**contact)]),signature='sasas') info.append(nickname) else: logger.info(repr(contact)) nickname = dbus.Struct(('nickname', [], [u'{screen_name}'.format(**contact)]),signature='sasas') info.append(nickname) return info
def Permissions(self): type_map = { 'w': 'writable', 'r': 'read-only', 'R': 'Read-only activation of non-read-only volume', '-': 'Unspecified' } return dbus.Struct((self.state.Attr[1], type_map[self.state.Attr[1]]), signature="(ss)")