Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 703d19c in mainline for uspace/drv/test1/test1.c


Ignore:
Timestamp:
2010-11-30T14:21:47Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
2edcb63
Parents:
5bee897
Message:

A bit of refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/test1/test1.c

    r5bee897 r703d19c  
    4949};
    5050
     51/** Register child and inform user about it.
     52 *
     53 * @param parent Parent device.
     54 * @param message Message for the user.
     55 * @param name Device name.
     56 * @param match_id Device match id.
     57 * @param score Device match score.
     58 */
     59static void register_child_verbose(device_t *parent, const char *message,
     60    const char *name, const char *match_id, int match_score)
     61{
     62        printf(NAME ": registering child device `%s': %s.\n",
     63           name, message);
     64
     65        int rc = child_device_register_wrapper(parent, name,
     66            match_id, match_score);
     67
     68        if (rc != EOK) {
     69                printf(NAME ": failed to register child `%s' (%s).\n",
     70                    name, str_error(rc));
     71        }
     72}
     73
    5174/** Callback when new device is passed to this driver.
    5275 * This function is the body of the test: it shall register new child
     
    6891static int add_device(device_t *dev)
    6992{
    70         int rc;
    7193        printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
    7294            dev->name, (int) dev->handle);
    7395
     96        add_device_to_class(dev, "virtual");
     97
    7498        if (dev->parent == NULL) {
    75                 printf(NAME ": cloning myself ;-).\n");
    76                 rc = child_device_register_wrapper(dev, "clone",
     99                register_child_verbose(dev, "cloning myself ;-)", "clone",
    77100                    "virtual&test1", 10);
    78                 if (rc != EOK) {
    79                         printf(NAME ": failed to register clone (%s).\n",
    80                             str_error(rc));
    81                 }
    82101        } else if (str_cmp(dev->name, "clone") == 0) {
    83                 printf(NAME ": registering child device run by the same task.\n");
    84                 rc = child_device_register_wrapper(dev, "child",
     102                register_child_verbose(dev, "run by the same task", "child",
    85103                    "virtual&test1&child", 10);
    86                 if (rc != EOK) {
    87                         printf(NAME ": failed to register child (%s).\n",
    88                             str_error(rc));
    89                 }
    90104        }
    91105
Note: See TracChangeset for help on using the changeset viewer.