Esempio n. 1
0
func match(updatePtrs []mojom.Update_Pointer, lost bool, wants ...mojom.Advertisement) error {
	updateMap := make(map[[internal.AdIdLen]uint8]mojom.Update)
	updates := make([]mojom.Update, 0)
	for _, ptr := range updatePtrs {
		update := mojom.NewUpdateProxy(ptr, bindings.GetAsyncWaiter())
		defer update.Close_Proxy()

		id, _ := update.GetId()
		updateMap[id] = update
		updates = append(updates, update)
	}
	for _, want := range wants {
		update := updateMap[*want.Id]
		if update == nil {
			break
		}
		if got, _ := update.IsLost(); got != lost {
			break
		}
		if !updateEqual(update, want) {
			break
		}
		delete(updateMap, *want.Id)
	}
	if len(updateMap) == 0 {
		return nil
	}
	return fmt.Errorf("Match failed; got %v, but wanted %v", updatesToDebugString(updates), adsToDebugString(wants))
}
Esempio n. 2
0
func (*scanHandler) OnUpdate(ptr discovery.Update_Pointer) error {
	uProxy := discovery.NewUpdateProxy(ptr, bindings.GetAsyncWaiter())
	defer uProxy.Close_Proxy()

	tag := "Found"
	if lost, _ := uProxy.IsLost(); lost {
		tag = "Lost"
	}
	id, _ := uProxy.GetId()
	interfaceName, _ := uProxy.GetInterfaceName()
	addresses, _ := uProxy.GetAddresses()
	attribute, _ := uProxy.GetAttribute("foo")
	attachmentHandle, _ := uProxy.GetAttachment("bar")
	_, attachment := attachmentHandle.ReadData(system.MOJO_READ_DATA_FLAG_NONE)
	attachmentHandle.Close()

	log.Printf("%s %x: {InterfaceName: %q, Addresses: %q, Attribute[\"foo\"]: %q, Attachment[\"bar\"]: 0x%x}", tag, id, interfaceName, addresses, attribute, attachment)
	return nil
}