Ignore:
Timestamp:
2010-10-10T11:53:05Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b8100da
Parents:
bc9a629
Message:

Virtual HCD refactoring

Splitted into more files, added more comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hw/bus/usb/hcd/virtual/devices.c

    rbc9a629 rb371844  
    3131 */
    3232/** @file
    33  * @brief
     33 * @brief Virtual device management (implementation).
    3434 */
    3535
     
    5353LIST_INITIALIZE(devices);
    5454
     55/** Recognise device by id.
     56 *
     57 * @param id Device id.
     58 * @param phone Callback phone.
     59 */
     60virtdev_connection_t *virtdev_recognise(int id, int phone)
     61{
     62        virtdev_connection_t * dev = NULL;
     63        switch (id) {
     64                case USB_VIRTDEV_KEYBOARD_ID:
     65                        dev = virtdev_add_device(
     66                            USB_VIRTDEV_KEYBOARD_ADDRESS, phone);
     67                        break;
     68                default:
     69                        break;
     70        }
     71       
     72        /*
     73         * We do not want to mess-up the virtdev_add_device() as
     74         * the id is needed only before device probing/detection
     75         * is implemented.
     76         *
     77         * However, that does not mean that this will happen soon.
     78         */
     79        if (dev) {
     80                dev->id = id;
     81        }
     82       
     83        return dev;
     84}
     85
     86/** Find virtual device by its USB address.
     87 *
     88 * @retval NULL No virtual device at given address.
     89 */
    5590virtdev_connection_t *virtdev_find_by_address(usb_address_t address)
    5691{
     
    67102}
    68103
     104/** Create virtual device.
     105 *
     106 * @param address USB address.
     107 * @param phone Callback phone.
     108 * @return New device.
     109 * @retval NULL Out of memory or address already occupied.
     110 */
    69111virtdev_connection_t *virtdev_add_device(usb_address_t address, int phone)
    70112{
     113        link_t *pos;
     114        list_foreach(pos, &devices) {
     115                virtdev_connection_t *dev
     116                    = list_get_instance(pos, virtdev_connection_t, link);
     117                if (dev->address == address) {
     118                        return NULL;
     119                }
     120        }
     121       
    71122        virtdev_connection_t *dev = (virtdev_connection_t *)
    72123            malloc(sizeof(virtdev_connection_t));
     
    78129}
    79130
    80  void virtdev_destroy_device(virtdev_connection_t *dev)
     131/** Destroy virtual device.
     132 */
     133void virtdev_destroy_device(virtdev_connection_t *dev)
    81134{
    82135        list_remove(&dev->link);
Note: See TracChangeset for help on using the changeset viewer.