int vbd_part_create(vbd_t *vbd, service_id_t disk, vbd_part_spec_t *pspec, vbd_part_id_t *rpart) { async_exch_t *exch; sysarg_t retval; ipc_call_t answer; exch = async_exchange_begin(vbd->sess); aid_t req = async_send_1(exch, VBD_PART_CREATE, disk, &answer); int rc = async_data_write_start(exch, pspec, sizeof(vbd_part_spec_t)); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return EIO; } async_wait_for(req, &retval); if (retval != EOK) return EIO; *rpart = (vbd_part_id_t)IPC_GET_ARG1(answer); return EOK; }
/** Get list of IDs into a buffer of fixed size. * * @param vbd Virtual Block Device * @param method IPC method * @param arg1 First argument * @param id_buf Buffer to store IDs * @param buf_size Buffer size * @param act_size Place to store actual size of complete data. * * @return EOK on success or negative error code. */ static int vbd_get_ids_once(vbd_t *vbd, sysarg_t method, sysarg_t arg1, sysarg_t *id_buf, size_t buf_size, size_t *act_size) { async_exch_t *exch = async_exchange_begin(vbd->sess); ipc_call_t answer; aid_t req = async_send_1(exch, method, arg1, &answer); int rc = async_data_read_start(exch, id_buf, buf_size); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return rc; } sysarg_t retval; async_wait_for(req, &retval); if (retval != EOK) { return retval; } *act_size = IPC_GET_ARG1(answer); return EOK; }
/** Set preset files for the program. * * Sets the vector of preset files to be passed to the loaded * program. By convention, the first three files represent stdin, * stdout and stderr respectively. * * @param ldr Loader connection structure. * @param files NULL-terminated array of pointers to files. * * @return Zero on success or negative error code. * */ int loader_set_files(loader_t *ldr, int * const files[]) { /* Send serialized files to the loader */ async_exch_t *exch = async_exchange_begin(ldr->sess); async_exch_t *vfs_exch = vfs_exchange_begin(); int i; for (i = 0; files[i]; i++); ipc_call_t answer; aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); sysarg_t rc = EOK; for (i = 0; files[i]; i++) { rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i], 0, vfs_exch); if (rc != EOK) break; } vfs_exchange_end(vfs_exch); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return (int) rc; } async_wait_for(req, &rc); return (int) rc; }
/** Send message via UDP association. * * @param assoc Association * @param dest Destination endpoint or @c NULL to use association's remote ep. * @param data Message data * @param bytes Message size in bytes * * @return EOK on success or negative error code */ int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data, size_t bytes) { async_exch_t *exch; exch = async_exchange_begin(assoc->udp->sess); aid_t req = async_send_1(exch, UDP_ASSOC_SEND_MSG, assoc->id, NULL); sysarg_t rc = async_data_write_start(exch, (void *)dest, sizeof(inet_ep_t)); if (rc != EOK) { async_exchange_end(exch); async_forget(req); return rc; } rc = async_data_write_start(exch, data, bytes); if (rc != EOK) { async_forget(req); return rc; } async_exchange_end(exch); if (rc != EOK) { async_forget(req); return rc; } async_wait_for(req, &rc); return rc; }
/** Copy string to clipboard. * * Sets the clipboard contents to @a str. Passing an empty string or NULL * makes the clipboard empty. * * @param str String to put to clipboard or NULL. * * @return Zero on success or negative error code. * */ int clipboard_put_str(const char *str) { size_t size = str_size(str); if (size == 0) { async_exch_t *exch = clip_exchange_begin(); sysarg_t rc = async_req_1_0(exch, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_NONE); clip_exchange_end(exch); return (int) rc; } else { async_exch_t *exch = clip_exchange_begin(); aid_t req = async_send_1(exch, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA, NULL); sysarg_t rc = async_data_write_start(exch, (void *) str, size); clip_exchange_end(exch); if (rc != EOK) { sysarg_t rc_orig; async_wait_for(req, &rc_orig); if (rc_orig == EOK) return (int) rc; else return (int) rc_orig; } async_wait_for(req, &rc); return (int) rc; } }
static int loc_category_get_ids_once(sysarg_t method, sysarg_t arg1, sysarg_t *id_buf, size_t buf_size, size_t *act_size) { async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); ipc_call_t answer; aid_t req = async_send_1(exch, method, arg1, &answer); int rc = async_data_read_start(exch, id_buf, buf_size); loc_exchange_end(exch); if (rc != EOK) { async_forget(req); return rc; } sysarg_t retval; async_wait_for(req, &retval); if (retval != EOK) { return retval; } *act_size = IPC_GET_ARG1(answer); return EOK; }
/** Connect to specified network. * * @param[in] dev_sess Device session. * @param[in] ssid_start Network SSID prefix. * @param[in] password Network password (pass empty string if not needed). * * @return EOK If the operation was successfully completed, * negative error code otherwise. * */ int ieee80211_connect(async_sess_t *dev_sess, char *ssid_start, char *password) { assert(ssid_start); sysarg_t rc_orig; async_exch_t *exch = async_exchange_begin(dev_sess); aid_t aid = async_send_1(exch, DEV_IFACE_ID(IEEE80211_DEV_IFACE), IEEE80211_CONNECT, NULL); sysarg_t rc = async_data_write_start(exch, ssid_start, str_size(ssid_start) + 1); if (rc != EOK) { async_exchange_end(exch); async_wait_for(aid, &rc_orig); if (rc_orig == EOK) return (int) rc; return (int) rc_orig; } // FIXME: Typecasting string literal if (password == NULL) password = (char *) ""; rc = async_data_write_start(exch, password, str_size(password) + 1); if (rc != EOK) { async_exchange_end(exch); async_wait_for(aid, &rc_orig); if (rc_orig == EOK) return (int) rc; return (int) rc_orig; } async_exchange_end(exch); async_wait_for(aid, &rc); if (rc != EOK) return rc; /* Send DHCP discover. */ nic_address_t wifi_mac; rc = nic_get_address(dev_sess, &wifi_mac); if (rc != EOK) return rc; sysarg_t link_id = get_link_id(wifi_mac.address); if (link_id == ((sysarg_t) -1)) return EINVAL; rc = dhcp_discover(link_id); return (int) rc; }
/** Read to or write from device. * * Helper function to read to or write from a device * using its character interface. * * @param sess Session to the device. * @param buf Buffer for the data read from or written to the device. * @param size Maximum size of data (in bytes) to be read or written. * @param read Read from the device if true, write to it otherwise. * * @return Non-negative number of bytes actually read from or * written to the device on success, negative error number * otherwise. * */ static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read) { ipc_call_t answer; aid_t req; int ret; async_exch_t *exch = async_exchange_begin(sess); if (read) { req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_DEV_READ, &answer); ret = async_data_read_start(exch, buf, size); } else { req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_DEV_WRITE, &answer); ret = async_data_write_start(exch, buf, size); } async_exchange_end(exch); sysarg_t rc; if (ret != EOK) { async_wait_for(req, &rc); if (rc == EOK) return (ssize_t) ret; return (ssize_t) rc; } async_wait_for(req, &rc); ret = (int) rc; if (ret != EOK) return (ssize_t) ret; return (ssize_t) IPC_GET_ARG1(answer); }
size_t loc_get_services(service_id_t ns_handle, loc_sdesc_t **data) { /* Loop until read is succesful */ while (true) { async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); size_t count = loc_count_services_internal(exch, ns_handle); loc_exchange_end(exch); if (count == 0) return 0; loc_sdesc_t *devs = (loc_sdesc_t *) calloc(count, sizeof(loc_sdesc_t)); if (devs == NULL) return 0; exch = loc_exchange_begin(LOC_PORT_CONSUMER); ipc_call_t answer; aid_t req = async_send_1(exch, LOC_GET_SERVICES, ns_handle, &answer); int rc = async_data_read_start(exch, devs, count * sizeof(loc_sdesc_t)); loc_exchange_end(exch); if (rc == EOVERFLOW) { /* * Number of services has changed since * the last call of LOC_GET_SERVICE_COUNT */ free(devs); continue; } if (rc != EOK) { async_forget(req); free(devs); return 0; } sysarg_t retval; async_wait_for(req, &retval); if (retval != EOK) return 0; *data = devs; return count; } }
/** Set the address of the device (e.g. MAC on Ethernet) * * @param[in] dev_sess * @param[in] address Pointer to the address * * @return EOK If the operation was successfully completed * */ int nic_set_address(async_sess_t *dev_sess, const nic_address_t *address) { assert(address); async_exch_t *exch = async_exchange_begin(dev_sess); aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_SET_ADDRESS, NULL); int rc = async_data_write_start(exch, address, sizeof(nic_address_t)); async_exchange_end(exch); sysarg_t res; async_wait_for(aid, &res); if (rc != EOK) return rc; return (int) res; }
/** Send frame from NIC * * @param[in] dev_sess * @param[in] data Frame data * @param[in] size Frame size in bytes * * @return EOK If the operation was successfully completed * */ int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size) { async_exch_t *exch = async_exchange_begin(dev_sess); ipc_call_t answer; aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_SEND_MESSAGE, &answer); sysarg_t retval = async_data_write_start(exch, data, size); async_exchange_end(exch); if (retval != EOK) { async_forget(req); return retval; } async_wait_for(req, &retval); return retval; }
/** Create callback connection from NIC service * * @param[in] dev_sess * @param[in] device_id * * @return EOK If the operation was successfully completed * */ int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun, void *carg) { ipc_call_t answer; int rc; sysarg_t retval; async_exch_t *exch = async_exchange_begin(dev_sess); aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_CALLBACK_CREATE, &answer); rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg); if (rc != EOK) { async_forget(req); return rc; } async_exchange_end(exch); async_wait_for(req, &retval); return (int) retval; }
/** Get object name. * * Provided ID of an object, return its name. * * @param method IPC method * @param id Object ID * @param name Place to store pointer to new string. Caller should * free it using free(). * @return EOK on success or negative error code */ static int loc_get_name_internal(sysarg_t method, sysarg_t id, char **name) { async_exch_t *exch; char name_buf[LOC_NAME_MAXLEN + 1]; ipc_call_t dreply; size_t act_size; sysarg_t dretval; *name = NULL; exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); ipc_call_t answer; aid_t req = async_send_1(exch, method, id, &answer); aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply); async_wait_for(dreq, &dretval); loc_exchange_end(exch); if (dretval != EOK) { async_forget(req); return dretval; } sysarg_t retval; async_wait_for(req, &retval); if (retval != EOK) return retval; act_size = IPC_GET_ARG2(dreply); assert(act_size <= LOC_NAME_MAXLEN); name_buf[act_size] = '\0'; *name = str_dup(name_buf); if (*name == NULL) return ENOMEM; return EOK; }
/** * Register a named application context to the audio server. * @param sess Valid audio session. * @param name Valid string identifier * @param record True if the application context wishes to receive data. * @return Valid ID on success, Error code on failure. */ hound_context_id_t hound_service_register_context(hound_sess_t *sess, const char *name, bool record) { assert(sess); assert(name); ipc_call_t call; async_exch_t *exch = async_exchange_begin(sess); aid_t mid = async_send_1(exch, IPC_M_HOUND_CONTEXT_REGISTER, record, &call); int ret = mid ? EOK : EPARTY; if (ret == EOK) ret = async_data_write_start(exch, name, str_size(name)); else async_forget(mid); if (ret == EOK) async_wait_for(mid, (sysarg_t *)&ret); async_exchange_end(exch); return ret == EOK ? (hound_context_id_t)IPC_GET_ARG1(call) : ret; }
/** Get disk information. */ int vbd_disk_info(vbd_t *vbd, service_id_t sid, vbd_disk_info_t *vinfo) { async_exch_t *exch; sysarg_t retval; ipc_call_t answer; exch = async_exchange_begin(vbd->sess); aid_t req = async_send_1(exch, VBD_DISK_INFO, sid, &answer); int rc = async_data_read_start(exch, vinfo, sizeof(vbd_disk_info_t)); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return EIO; } async_wait_for(req, &retval); if (retval != EOK) return EIO; return EOK; }
int vbd_part_get_info(vbd_t *vbd, vbd_part_id_t part, vbd_part_info_t *pinfo) { async_exch_t *exch; sysarg_t retval; ipc_call_t answer; exch = async_exchange_begin(vbd->sess); aid_t req = async_send_1(exch, VBD_PART_GET_INFO, part, &answer); int rc = async_data_read_start(exch, pinfo, sizeof(vbd_part_info_t)); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return EIO; } async_wait_for(req, &retval); if (retval != EOK) return EIO; return EOK; }
int bd_read_toc(bd_t *bd, uint8_t session, void *buf, size_t size) { async_exch_t *exch = async_exchange_begin(bd->sess); ipc_call_t answer; aid_t req = async_send_1(exch, BD_READ_TOC, session, &answer); int rc = async_data_read_start(exch, buf, size); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return rc; } sysarg_t retval; async_wait_for(req, &retval); if (retval != EOK) return retval; return EOK; }
/** Create a new (sub-) log. * * This function always returns a valid log_t. In case of errors, * @c parent is returned and errors are silently ignored. * * @param name Log name under which message will be reported (appended to parents name). * @param parent Parent log. * @return Opaque identifier of the newly created log. */ log_t log_create(const char *name, log_t parent) { async_exch_t *exchange = async_exchange_begin(logger_session); if (exchange == NULL) return parent; if (parent == LOG_DEFAULT) parent = default_log_id; ipc_call_t answer; aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_LOG, parent, &answer); int rc = async_data_write_start(exchange, name, str_size(name)); sysarg_t reg_msg_rc; async_wait_for(reg_msg, ®_msg_rc); async_exchange_end(exchange); if ((rc != EOK) || (reg_msg_rc != EOK)) return parent; return IPC_GET_ARG1(answer); }
/** Read part of received message. * * @param rmsg Received message * @param off Start offset * @param buf Buffer for storing data * @param bsize Buffer size * * @return EOK on success or negative error code. */ int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize) { async_exch_t *exch; ipc_call_t answer; exch = async_exchange_begin(rmsg->udp->sess); aid_t req = async_send_1(exch, UDP_RMSG_READ, off, &answer); int rc = async_data_read_start(exch, buf, bsize); async_exchange_end(exch); if (rc != EOK) { async_forget(req); return rc; } sysarg_t retval; async_wait_for(req, &retval); if (retval != EOK) { return retval; } return EOK; }
/** Set the current time * * @param sess Session of the device * @param t The current time that will be written to the device * * @return EOK on success or a negative error code */ int clock_dev_time_set(async_sess_t *sess, struct tm *t) { aid_t req; int ret; async_exch_t *exch = async_exchange_begin(sess); req = async_send_1(exch, DEV_IFACE_ID(CLOCK_DEV_IFACE), CLOCK_DEV_TIME_SET, NULL); ret = async_data_write_start(exch, t, sizeof(*t)); async_exchange_end(exch); sysarg_t rc; if (ret != EOK) { async_forget(req); return ret; } async_wait_for(req, &rc); return (int)rc; }
/** Get a copy of clipboard contents. * * Returns a new string that can be deallocated with free(). * * @param str Here pointer to the newly allocated string is stored. * * @return Zero on success or negative error code. * */ int clipboard_get_str(char **str) { /* Loop until clipboard read succesful */ while (true) { async_exch_t *exch = clip_exchange_begin(); sysarg_t size; sysarg_t tag; sysarg_t rc = async_req_0_2(exch, CLIPBOARD_CONTENT, &size, &tag); clip_exchange_end(exch); if (rc != EOK) return (int) rc; char *sbuf; switch (tag) { case CLIPBOARD_TAG_NONE: sbuf = malloc(1); if (sbuf == NULL) return ENOMEM; sbuf[0] = 0; *str = sbuf; return EOK; case CLIPBOARD_TAG_DATA: sbuf = malloc(size + 1); if (sbuf == NULL) return ENOMEM; exch = clip_exchange_begin(); aid_t req = async_send_1(exch, CLIPBOARD_GET_DATA, tag, NULL); rc = async_data_read_start(exch, (void *) sbuf, size); clip_exchange_end(exch); if ((int) rc == EOVERFLOW) { /* * The data in the clipboard has changed since * the last call of CLIPBOARD_CONTENT */ break; } if (rc != EOK) { sysarg_t rc_orig; async_wait_for(req, &rc_orig); if (rc_orig == EOK) return (int) rc; else return (int) rc_orig; } async_wait_for(req, &rc); if (rc == EOK) { sbuf[size] = 0; *str = sbuf; } return rc; default: return EINVAL; } } }