Changeset 0cc32f2 in mainline for uspace/lib


Ignore:
Timestamp:
2011-08-18T18:47:54Z (14 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1f44b056, d7427a7e
Parents:
1d2a1a9 (diff), f55b12b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix changes.

Location:
uspace/lib
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/devman.c

    r1d2a1a9 r0cc32f2  
    271271}
    272272
    273 int devman_add_device_to_class(devman_handle_t devman_handle,
    274     const char *class_name)
     273int devman_add_device_to_category(devman_handle_t devman_handle,
     274    const char *cat_name)
    275275{
    276276        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
    277277       
    278278        ipc_call_t answer;
    279         aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CLASS,
     279        aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY,
    280280            devman_handle, &answer);
    281         sysarg_t retval = async_data_write_start(exch, class_name,
    282             str_size(class_name));
     281        sysarg_t retval = async_data_write_start(exch, cat_name,
     282            str_size(cat_name));
    283283       
    284284        devman_exchange_end(exch);
     
    333333                exch = devman_exchange_begin(DEVMAN_CLIENT);
    334334                if (exch == NULL)
    335                         return errno;
     335                        return ENOMEM;
    336336        }
    337337       
     
    364364}
    365365
    366 int devman_device_get_handle_by_class(const char *classname,
    367     const char *devname, devman_handle_t *handle, unsigned int flags)
    368 {
    369         async_exch_t *exch;
    370        
    371         if (flags & IPC_FLAG_BLOCKING)
    372                 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
    373         else {
    374                 exch = devman_exchange_begin(DEVMAN_CLIENT);
    375                 if (exch == NULL)
    376                         return errno;
    377         }
    378        
    379         ipc_call_t answer;
    380         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    381             flags, &answer);
    382         sysarg_t retval = async_data_write_start(exch, classname,
    383             str_size(classname));
    384        
    385         if (retval != EOK) {
    386                 devman_exchange_end(exch);
    387                 async_wait_for(req, NULL);
    388                 return retval;
    389         }
    390        
    391         retval = async_data_write_start(exch, devname,
    392             str_size(devname));
    393        
    394         devman_exchange_end(exch);
    395        
    396         if (retval != EOK) {
    397                 async_wait_for(req, NULL);
    398                 return retval;
    399         }
    400        
    401         async_wait_for(req, &retval);
    402        
    403         if (retval != EOK) {
    404                 if (handle != NULL)
    405                         *handle = (devman_handle_t) -1;
    406                
    407                 return retval;
    408         }
    409        
    410         if (handle != NULL)
    411                 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
    412        
    413         return retval;
    414 }
    415 
    416366int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
    417367{
    418368        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
    419369        if (exch == NULL)
    420                 return errno;
     370                return ENOMEM;
    421371       
    422372        ipc_call_t answer;
     
    463413}
    464414
     415int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle)
     416{
     417        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     418        if (exch == NULL)
     419                return ENOMEM;
     420       
     421        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
     422            sid, handle);
     423       
     424        devman_exchange_end(exch);
     425        return (int) retval;
     426}
     427
    465428/** @}
    466429 */
  • uspace/lib/c/generic/loc.c

    r1d2a1a9 r0cc32f2  
    4545static FIBRIL_MUTEX_INITIALIZE(loc_consumer_mutex);
    4646
     47static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
     48static bool loc_callback_created = false;
     49
    4750static async_sess_t *loc_supp_block_sess = NULL;
    4851static async_sess_t *loc_cons_block_sess = NULL;
     
    5154static async_sess_t *loc_consumer_sess = NULL;
    5255
     56static loc_cat_change_cb_t cat_change_cb = NULL;
     57
     58static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     59{
     60        loc_cat_change_cb_t cb_fun;
     61       
     62        while (true) {
     63                ipc_call_t call;
     64                ipc_callid_t callid = async_get_call(&call);
     65               
     66                if (!IPC_GET_IMETHOD(call)) {
     67                        /* TODO: Handle hangup */
     68                        return;
     69                }
     70               
     71                int retval;
     72               
     73                switch (IPC_GET_IMETHOD(call)) {
     74                case LOC_EVENT_CAT_CHANGE:
     75                        fibril_mutex_lock(&loc_callback_mutex);
     76                        cb_fun = cat_change_cb;
     77                        if (cb_fun != NULL) {
     78                                (*cb_fun)();
     79                        }
     80                        fibril_mutex_unlock(&loc_callback_mutex);
     81                        retval = 0;
     82                        break;
     83                default:
     84                        retval = ENOTSUP;
     85                }
     86               
     87                async_answer_0(callid, retval);
     88        }
     89}
     90
     91
    5392static void clone_session(fibril_mutex_t *mtx, async_sess_t *src,
    5493    async_sess_t **dst)
     
    6099       
    61100        fibril_mutex_unlock(mtx);
     101}
     102
     103static int loc_callback_create(void)
     104{
     105        async_exch_t *exch;
     106        sysarg_t retval;
     107        int rc = EOK;
     108
     109        fibril_mutex_lock(&loc_callback_mutex);
     110       
     111        if (!loc_callback_created) {
     112                exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     113               
     114                ipc_call_t answer;
     115                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
     116                async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     117                loc_exchange_end(exch);
     118               
     119                async_wait_for(req, &retval);
     120                if (rc != EOK)
     121                        goto done;
     122               
     123                if (retval != EOK) {
     124                        rc = retval;
     125                        goto done;
     126                }
     127               
     128                loc_callback_created = true;
     129        }
     130       
     131        rc = EOK;
     132done:
     133        fibril_mutex_unlock(&loc_callback_mutex);
     134        return rc;
    62135}
    63136
     
    291364}
    292365
    293 /** Get service name.
    294  *
    295  * Provided ID of a service, return its name.
    296  *
    297  * @param svc_id        Service ID
     366/** Get object name.
     367 *
     368 * Provided ID of an object, return its name.
     369 *
     370 * @param method        IPC method
     371 * @param id            Object ID
    298372 * @param name          Place to store pointer to new string. Caller should
    299373 *                      free it using free().
    300374 * @return              EOK on success or negative error code
    301375 */
    302 int loc_service_get_name(service_id_t svc_id, char **name)
     376static int loc_get_name_internal(sysarg_t method, sysarg_t id, char **name)
    303377{
    304378        async_exch_t *exch;
     
    312386       
    313387        ipc_call_t answer;
    314         aid_t req = async_send_1(exch, LOC_SERVICE_GET_NAME, svc_id, &answer);
     388        aid_t req = async_send_1(exch, method, id, &answer);
    315389        aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN,
    316390            &dreply);
     
    341415}
    342416
     417/** Get category name.
     418 *
     419 * Provided ID of a service, return its name.
     420 *
     421 * @param cat_id        Category ID
     422 * @param name          Place to store pointer to new string. Caller should
     423 *                      free it using free().
     424 * @return              EOK on success or negative error code
     425 */
     426int loc_category_get_name(category_id_t cat_id, char **name)
     427{
     428        return loc_get_name_internal(LOC_CATEGORY_GET_NAME, cat_id, name);
     429}
     430
     431/** Get service name.
     432 *
     433 * Provided ID of a service, return its name.
     434 *
     435 * @param svc_id        Service ID
     436 * @param name          Place to store pointer to new string. Caller should
     437 *                      free it using free().
     438 * @return              EOK on success or negative error code
     439 */
     440int loc_service_get_name(service_id_t svc_id, char **name)
     441{
     442        return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name);
     443}
    343444
    344445int loc_namespace_get_id(const char *name, service_id_t *handle,
     
    749850            data, count);
    750851}
     852
     853int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
     854{
     855        if (loc_callback_create() != EOK)
     856                return EIO;
     857
     858        cat_change_cb = cb_fun;
     859        return EOK;
     860}
  • uspace/lib/c/include/devman.h

    r1d2a1a9 r0cc32f2  
    3838
    3939#include <ipc/devman.h>
     40#include <ipc/loc.h>
    4041#include <async.h>
    4142#include <bool.h>
     
    5657extern int devman_device_get_handle(const char *, devman_handle_t *,
    5758    unsigned int);
    58 extern int devman_device_get_handle_by_class(const char *, const char *,
    59     devman_handle_t *, unsigned int);
    6059extern int devman_get_device_path(devman_handle_t, char *, size_t);
    6160
    62 extern int devman_add_device_to_class(devman_handle_t, const char *);
     61extern int devman_add_device_to_category(devman_handle_t, const char *);
     62extern int devman_fun_sid_to_handle(service_id_t, devman_handle_t *);
    6363
    6464#endif
  • uspace/lib/c/include/ipc/devman.h

    r1d2a1a9 r0cc32f2  
    138138        DEVMAN_ADD_FUNCTION,
    139139        DEVMAN_ADD_MATCH_ID,
    140         DEVMAN_ADD_DEVICE_TO_CLASS
     140        DEVMAN_ADD_DEVICE_TO_CATEGORY
    141141
    142142} driver_to_devman_t;
     
    149149typedef enum {
    150150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
    151         DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    152         DEVMAN_DEVICE_GET_DEVICE_PATH
     151        DEVMAN_DEVICE_GET_DEVICE_PATH,
     152        DEVMAN_FUN_SID_TO_HANDLE
    153153} client_to_devman_t;
    154154
  • uspace/lib/c/include/ipc/loc.h

    r1d2a1a9 r0cc32f2  
    5757        LOC_SERVICE_GET_NAME,
    5858        LOC_NAMESPACE_GET_ID,
     59        LOC_CALLBACK_CREATE,
    5960        LOC_CATEGORY_GET_ID,
     61        LOC_CATEGORY_GET_NAME,
    6062        LOC_CATEGORY_GET_SVCS,
    6163        LOC_ID_PROBE,
     
    6870        LOC_GET_SERVICES
    6971} loc_request_t;
     72
     73typedef enum {
     74        LOC_EVENT_CAT_CHANGE = IPC_FIRST_USER_METHOD
     75} loc_event_t;
    7076
    7177/** Ports provided by location service.
  • uspace/lib/c/include/loc.h

    r1d2a1a9 r0cc32f2  
    4040#include <bool.h>
    4141
     42typedef void (*loc_cat_change_cb_t)(void);
     43
    4244extern async_exch_t *loc_exchange_begin_blocking(loc_interface_t);
    4345extern async_exch_t *loc_exchange_begin(loc_interface_t);
     
    7375extern size_t loc_get_services(service_id_t, loc_sdesc_t **);
    7476extern int loc_get_categories(category_id_t **, size_t *);
     77extern int loc_register_cat_change_cb(loc_cat_change_cb_t);
    7578
    7679
  • uspace/lib/drv/generic/driver.c

    r1d2a1a9 r0cc32f2  
    635635}
    636636
    637 /** Add exposed function to class.
     637/** Add exposed function to category.
    638638 *
    639639 * Must only be called when the function is bound.
    640640 */
    641 int ddf_fun_add_to_class(ddf_fun_t *fun, const char *class_name)
     641int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name)
    642642{
    643643        assert(fun->bound == true);
    644644        assert(fun->ftype == fun_exposed);
    645645       
    646         return devman_add_device_to_class(fun->handle, class_name);
     646        return devman_add_device_to_category(fun->handle, cat_name);
    647647}
    648648
  • uspace/lib/drv/include/ddf/driver.h

    r1d2a1a9 r0cc32f2  
    151151extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
    152152
    153 extern int ddf_fun_add_to_class(ddf_fun_t *, const char *);
     153extern int ddf_fun_add_to_category(ddf_fun_t *, const char *);
    154154
    155155#endif
  • uspace/lib/posix/pwd.c

    r1d2a1a9 r0cc32f2  
    5151
    5252/**
     53 * Retrieve next broken-down entry from the user database.
     54 *
    5355 * Since HelenOS doesn't have user accounts, this always returns
    5456 * the same made-up entry.
    5557 *
    56  * @return
     58 * @return Next user database entry or NULL if not possible. Since HelenOS
     59 *     doesn't have user accounts, this always returns the same made-up entry.
    5760 */
    5861struct posix_passwd *posix_getpwent(void)
     
    6770
    6871/**
    69  * "Rewind the user list".
     72 * Rewind the user list.
    7073 */
    7174void posix_setpwent(void)
     
    8689 *
    8790 * @param name Name of the entry.
    88  * @return
     91 * @return Either found entry or NULL if no such entry exists.
    8992 */
    9093struct posix_passwd *posix_getpwnam(const char *name)
     
    103106 *
    104107 * @param name Name of the entry.
    105  * @param pwd
    106  * @param buffer
    107  * @param bufsize
    108  * @param result
    109  * @return
     108 * @param pwd Original structure.
     109 * @param buffer Buffer for the strings referenced from the result structure.
     110 * @param bufsize Length of the buffer.
     111 * @param result Where to store updated structure.
     112 * @return Zero on success (either found or not found, but without an error),
     113 *     non-zero error number if error occured.
    110114 */
    111115int posix_getpwnam_r(const char *name, struct posix_passwd *pwd,
     
    129133 *
    130134 * @param uid UID of the entry.
    131  * @return
     135 * @return Either found entry or NULL if no such entry exists.
    132136 */
    133137struct posix_passwd *posix_getpwuid(posix_uid_t uid)
     
    144148 *
    145149 * @param uid UID of the entry.
    146  * @param pwd
    147  * @param buffer
    148  * @param bufsize
    149  * @param result
    150  * @return
     150 * @param pwd Original structure.
     151 * @param buffer Buffer for the strings referenced from the result structure.
     152 * @param bufsize Length of the buffer.
     153 * @param result Where to store updated structure.
     154 * @return Zero on success (either found or not found, but without an error),
     155 *     non-zero error number if error occured.
    151156 */
    152157int posix_getpwuid_r(posix_uid_t uid, struct posix_passwd *pwd,
  • uspace/lib/posix/string.c

    r1d2a1a9 r0cc32f2  
    4848
    4949/**
    50  * Decides whether s2 is a prefix of s1.
    51  *
    52  * @param s1 String in which to look for a prefix.
    53  * @param s2 Prefix string to look for.
    54  * @return True if s2 is a prefix of s1, false otherwise.
    55  */
    56 static bool begins_with(const char *s1, const char *s2)
    57 {
    58         while (*s1 == *s2 && *s2 != '\0') {
    59                 s1++;
    60                 s2++;
    61         }
    62        
    63         /* true if the end was reached */
    64         return *s2 == '\0';
    65 }
    66 
    67 /**
    6850 * The same as strpbrk, except it returns pointer to the nul terminator
    6951 * if no occurence is found.
     
    471453
    472454/**
    473  * Find a substring.
     455 * Find a substring. Uses Knuth-Morris-Pratt algorithm.
    474456 *
    475457 * @param s1 String in which to look for a substring.
     
    478460 *     not found.
    479461 */
    480 char *posix_strstr(const char *s1, const char *s2)
    481 {
    482         assert(s1 != NULL);
    483         assert(s2 != NULL);
    484 
    485         /* special case - needle is an empty string */
    486         if (*s2 == '\0') {
    487                 return (char *) s1;
    488         }
    489 
    490         // TODO: use faster algorithm
    491         /* check for prefix from every position - quadratic complexity */
    492         while (*s1 != '\0') {
    493                 if (begins_with(s1, s2)) {
    494                         return (char *) s1;
    495                 }
     462char *posix_strstr(const char *haystack, const char *needle)
     463{
     464        assert(haystack != NULL);
     465        assert(needle != NULL);
     466       
     467        /* Special case - needle is an empty string. */
     468        if (needle[0] == '\0') {
     469                return (char *) haystack;
     470        }
     471       
     472        /* Preprocess needle. */
     473        size_t nlen = posix_strlen(needle);
     474        size_t prefix_table[nlen + 1];
     475       
     476        {
     477                size_t i = 0;
     478                ssize_t j = -1;
    496479               
    497                 s1++;
     480                prefix_table[i] = j;
     481               
     482                while (i < nlen) {
     483                        while (j >= 0 && needle[i] != needle[j]) {
     484                                j = prefix_table[j];
     485                        }
     486                        i++; j++;
     487                        prefix_table[i] = j;
     488                }
     489        }
     490       
     491        /* Search needle using the precomputed table. */
     492        size_t npos = 0;
     493       
     494        for (size_t hpos = 0; haystack[hpos] != '\0'; ++hpos) {
     495                while (npos != 0 && haystack[hpos] != needle[npos]) {
     496                        npos = prefix_table[npos];
     497                }
     498               
     499                if (haystack[hpos] == needle[npos]) {
     500                        npos++;
     501                       
     502                        if (npos == nlen) {
     503                                return (char *) (haystack + hpos - nlen + 1);
     504                        }
     505                }
    498506        }
    499507       
  • uspace/lib/posix/string.h

    r1d2a1a9 r0cc32f2  
    8686extern size_t posix_strcspn(const char *s1, const char *s2);
    8787extern size_t posix_strspn(const char *s1, const char *s2);
    88 extern char *posix_strstr(const char *s1, const char *s2);
     88extern char *posix_strstr(const char *haystack, const char *needle);
    8989
    9090/* Collation Functions */
  • uspace/lib/usb/include/usb/hc.h

    r1d2a1a9 r0cc32f2  
    3838#include <sys/types.h>
    3939#include <ipc/devman.h>
     40#include <ipc/loc.h>
    4041#include <ddf/driver.h>
    4142#include <bool.h>
     
    6869    devman_handle_t *);
    6970
    70 int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *);
     71int usb_ddf_get_hc_handle_by_sid(service_id_t, devman_handle_t *);
    7172
    7273
  • uspace/lib/usb/include/usb/usb.h

    r1d2a1a9 r0cc32f2  
    174174} usb_packet_id;
    175175
    176 /** Class name for USB host controllers. */
    177 #define USB_HC_DDF_CLASS_NAME "usbhc"
     176/** Category for USB host controllers. */
     177#define USB_HC_CATEGORY "usbhc"
    178178
    179179#endif
  • uspace/lib/usb/src/hc.c

    r1d2a1a9 r0cc32f2  
    201201/** Get host controller handle by its class index.
    202202 *
    203  * @param class_index Class index for the host controller.
     203 * @param sid Service ID of the HC function.
    204204 * @param hc_handle Where to store the HC handle
    205205 *      (can be NULL for existence test only).
    206206 * @return Error code.
    207207 */
    208 int usb_ddf_get_hc_handle_by_class(size_t class_index,
    209     devman_handle_t *hc_handle)
    210 {
    211         char *class_index_str;
    212         devman_handle_t hc_handle_tmp;
     208int usb_ddf_get_hc_handle_by_sid(service_id_t sid, devman_handle_t *hc_handle)
     209{
     210        devman_handle_t handle;
    213211        int rc;
    214 
    215         rc = asprintf(&class_index_str, "%zu", class_index);
    216         if (rc < 0) {
    217                 return ENOMEM;
    218         }
    219         rc = devman_device_get_handle_by_class("usbhc", class_index_str,
    220             &hc_handle_tmp, 0);
    221         free(class_index_str);
    222         if (rc != EOK) {
    223                 return rc;
    224         }
    225 
    226         if (hc_handle != NULL) {
    227                 *hc_handle = hc_handle_tmp;
    228         }
    229 
    230         return EOK;
     212       
     213        rc = devman_fun_sid_to_handle(sid, &handle);
     214        if (hc_handle != NULL)
     215                *hc_handle = handle;
     216       
     217        return rc;
    231218}
    232219
  • uspace/lib/usb/src/resolve.c

    r1d2a1a9 r0cc32f2  
    4646    devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    4747{
    48         size_t class_index;
     48        uint64_t sid;
    4949        size_t address;
    5050        int rc;
    5151        char *ptr;
    5252
    53         rc = str_size_t(path, &ptr, 10, false, &class_index);
     53        rc = str_uint64(path, &ptr, 10, false, &sid);
    5454        if (rc != EOK) {
    5555                return false;
     
    6464                return false;
    6565        }
    66         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
     66        rc = usb_ddf_get_hc_handle_by_sid(sid, out_hc_handle);
    6767        if (rc != EOK) {
    6868                return false;
Note: See TracChangeset for help on using the changeset viewer.