// AddDevice adds a new Device to the robots collection of devices. Returns the
// added device.
977128
func (r *Robot) AddDevice(d Device) Device {
	*r.devices = append(*r.Devices(), d)
	return d
}
751452
func (m *PoolMetadata) GetDevice(ctx context.Context, name string) (*DeviceInfo, error) {
	var (
		dev DeviceInfo
		err error
	)

	err = m.db.View(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(devicesBucketName)
		return getObject(bucket, name, &dev)
	})

	return &dev, err
}
511135
func (m *PoolMetadata) AddDevice(ctx context.Context, info *DeviceInfo) error {
	return m.db.Update(func(tx *bolt.Tx) error {
		devicesBucket := tx.Bucket(devicesBucketName)

		// Make sure device name is unique
		if err := getObject(devicesBucket, info.Name, nil); err == nil {
			return ErrAlreadyExists
		}

		// Find next available device ID
		deviceID, err := getNextDeviceID(tx)
		if err != nil {
			return err
		}

		info.DeviceID = deviceID

		return putObject(devicesBucket, info.Name, info, false)
	})
}
1329183
func (m *metadataTracker) addFile(dev protocol.DeviceID, f FileIntf) {
	m.mut.Lock()
	defer m.mut.Unlock()

	m.dirty = true

	m.updateSeqLocked(dev, f)

	if f.IsInvalid() && f.FileLocalFlags() == 0 {
		// This is a remote invalid file; it does not count.
		return
	}

	if flags := f.FileLocalFlags(); flags == 0 {
		// Account regular files in the zero-flags bucket.
		m.addFileLocked(dev, 0, f)
	} else {
		// Account in flag specific buckets.
		eachFlagBit(flags, func(flag uint32) {
			m.addFileLocked(dev, flag, f)
		})
	}
}
610998
func (m *Machine) LinkLayerDevice(name string) (*LinkLayerDevice, error) {
	linkLayerDevices, closer := m.st.db().GetCollection(linkLayerDevicesC)
	defer closer()

	linkLayerDeviceDocID := m.linkLayerDeviceDocIDFromName(name)
	deviceAsString := m.deviceAsStringFromName(name)

	var doc linkLayerDeviceDoc
	err := linkLayerDevices.FindId(linkLayerDeviceDocID).One(&doc)
	if err == mgo.ErrNotFound {
		return nil, errors.NotFoundf("%s", deviceAsString)
	} else if err != nil {
		return nil, errors.Annotatef(err, "cannot get %s", deviceAsString)
	}
	return newLinkLayerDevice(m.st, doc), nil
}
103135
func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, transactionID uint64) (*devInfo, error) {
	logrus.Debugf("devmapper: registerDevice(%v, %v)", id, hash)
	info := &devInfo{
		Hash:          hash,
		DeviceID:      id,
		Size:          size,
		TransactionID: transactionID,
		Initialized:   false,
		devices:       devices,
	}

	devices.Devices[hash] = info

	if err := devices.saveMetadata(info); err != nil {
		// Try to remove unused device
		delete(devices.Devices, hash)
		return nil, err
	}

	return info, nil
}
430940
func (v VirtualMachine) EditDevice(ctx context.Context, device ...types.BaseVirtualDevice) error {
	return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationEdit, types.VirtualDeviceConfigSpecFileOperationReplace, device...)
}
770639
func (c *Container) AddDisk(name, path, source, pool string, readOnly bool) error {
	if _, ok := c.Devices[name]; ok {
		return errors.Errorf("container %q already has a device %q", c.Name, name)
	}

	if c.Devices == nil {
		c.Devices = map[string]device{}
	}
	c.Devices[name] = map[string]string{
		"path":   path,
		"source": source,
	}
	if pool != "" {
		c.Devices[name]["pool"] = pool
	}
	if readOnly {
		c.Devices[name]["readonly"] = "true"
	}
	return nil
}
386081
func (w *wrapper) IgnoredDevice(id protocol.DeviceID) bool {
	w.mut.Lock()
	defer w.mut.Unlock()
	for _, device := range w.cfg.IgnoredDevices {
		if device.ID == id {
			return true
		}
	}
	return false
}
1307509
func AddDevice(ephemeralId, publicKey, verificationCode string) error {
	return addNewDevice(ephemeralId, publicKey, verificationCode)
}
167745
func (s *NetworkDeviceService) AddNetworkDevice(p *AddNetworkDeviceParams) (*AddNetworkDeviceResponse, error) {
	resp, err := s.cs.newRequest("addNetworkDevice", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r AddNetworkDeviceResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
1009680
func NewMemberDevices(TeamMemberId string) *MemberDevices {
	s := new(MemberDevices)
	s.TeamMemberId = TeamMemberId
	return s
}
546168
func (s *CreateDeviceDefinitionVersionInput) SetDevices(v []*Device) *CreateDeviceDefinitionVersionInput {
	s.Devices = v
	return s
}
521305
func NewDevice(name string, database db.Database) (Device, error) {
	var e db.Entity
	var err error

	if e, err = database.EntityWithName(name); err != nil {
		if e, err = db.NewRandomEntityWithName(name); err == nil {
			err = database.SaveEntity(e)
		}
	}

	return &device{e}, err
}
547748
func (mc MongoClient) AddDevice(d contract.Device) (string, error) {
	s := mc.session.Copy()
	defer s.Close()

	col := s.DB(mc.database.Name).C(db.Device)

	// Check if the name exist (Device names must be unique)
	count, err := col.Find(bson.M{"name": d.Name}).Count()
	if err != nil {
		return "", errorMap(err)
	}
	if count > 0 {
		return "", db.ErrNotUnique
	}

	var mapped models.Device
	id, err := mapped.FromContract(d, mc, mc, mc, mc)
	if err != nil {
		return "", errors.New("FromContract failed")
	}

	mapped.TimestampForAdd()

	return id, errorMap(col.Insert(mapped))
}
352736
func (n *NetworkServerAPI) AddDeviceToMulticastGroup(ctx context.Context, req *ns.AddDeviceToMulticastGroupRequest) (*empty.Empty, error) {
	var devEUI lorawan.EUI64
	var mgID uuid.UUID
	copy(devEUI[:], req.DevEui)
	copy(mgID[:], req.MulticastGroupId)

	if err := storage.AddDeviceToMulticastGroup(storage.DB(), devEUI, mgID); err != nil {
		return nil, errToRPCError(err)
	}

	return &empty.Empty{}, nil
}
153264
func (s *DeviceEvent) SetDevice(v *Device) *DeviceEvent {
	s.Device = v
	return s
}