예제 #1
0
int nfc_fsm_event_post(int event, void * event_data, struct nfc_msg_cb *msg_cb)
{
    struct fsm_event_message * evt = (struct fsm_event_message *)
        balloc(sizeof(*evt), NULL);
    MESSAGE_ID(&evt->m) = NFC_FSM_EVENT_MESSAGE;
    MESSAGE_DST(&evt->m) = fsm_port_id;
    evt->event = event;
    evt->event_data = event_data;
    evt->msg_cb = msg_cb;
    return port_send_message(&evt->m);
}
예제 #2
0
/**
 * \brief send a message to handle_ipc_request_port()
 *
 * \param msgid the message id to generate. can be \ref IPC_MESSAGE_FREE
 *              or \ref IPC_MESSAGE_SEND
 * \param message the message data to send / free
 */
static int ipc_request_send(uint16_t msgid, void * message)
{
	OS_ERR_TYPE err = E_OS_OK;
	struct ipc_async_msg * msg =
		(struct ipc_async_msg *) balloc(sizeof(*msg), &err);
	if (err == E_OS_OK) {
		MESSAGE_ID(&msg->h) = msgid;
		MESSAGE_DST(&msg->h) = ipc_port;
		MESSAGE_SRC(&msg->h) = ipc_port;
		msg->data = message;
		port_send_message(&msg->h);
	}
	return err;
}
예제 #3
0
///-------------------------------------------------------------------------
// @brief 
///-------------------------------------------------------------------------
void RotatingBlades::handleMessage( const MessageSystem::Message& msg )
{
    UNUSEDPARAM(msg);
    //const ActivationMessage& activateMsg = (const ActivationMessage&)msg;
    //setActive(activateMsg.shouldActivate());
    if (msg.getMessageId() == MESSAGE_ID(CreatedRenderResourceMessage))
    {
        const MessageSystem::CreatedRenderResourceMessage& renderResourceMsg = static_cast<const MessageSystem::CreatedRenderResourceMessage&>(msg);
        renderResourceMsg.GetData();
        m_renderHandle = renderResourceMsg.GetData()->m_renderResourceHandle;
        //Store the render object reference we get back and the things it can do
        m_initialisationDone = true;
    }
}
예제 #4
0
int log_syntax_internal(const char *unit, int level,
                        const char *file, unsigned line, const char *func,
                        const char *config_file, unsigned config_line,
                        int error, const char *format, ...) {

        _cleanup_free_ char *msg = NULL;
        int r;
        va_list ap;

        va_start(ap, format);
        r = vasprintf(&msg, format, ap);
        va_end(ap);
        if (r < 0)
                return log_oom();

        if (unit)
                r = log_struct_internal(level,
                                        file, line, func,
                                        getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit,
                                        MESSAGE_ID(SD_MESSAGE_CONFIG_ERROR),
                                        "CONFIG_FILE=%s", config_file,
                                        "CONFIG_LINE=%u", config_line,
                                        "ERRNO=%d", error > 0 ? error : EINVAL,
                                        "MESSAGE=[%s:%u] %s", config_file, config_line, msg,
                                        NULL);
        else
                r = log_struct_internal(level,
                                        file, line, func,
                                        MESSAGE_ID(SD_MESSAGE_CONFIG_ERROR),
                                        "CONFIG_FILE=%s", config_file,
                                        "CONFIG_LINE=%u", config_line,
                                        "ERRNO=%d", error > 0 ? error : EINVAL,
                                        "MESSAGE=[%s:%u] %s", config_file, config_line, msg,
                                        NULL);

        return r;
}
예제 #5
0
/**
 * \brief this function is called in the context of the queue set by
 * ipc_async_init().
 * When the ipc_async_send_message() and ipc_async_free_message() are called,
 * A message is generated and sent to the port whose callback is this function.
 *
 * \param m the message to handle
 * \param data the parameter passed to port_set_handler()
 */
static void handle_ipc_request_port(struct message *m, void *data)
{
	struct ipc_async_msg * msg = (struct ipc_async_msg *)m;
	switch(MESSAGE_ID(&msg->h)) {
		case IPC_MESSAGE_SEND:
			pr_debug(LOG_MODULE_MAIN, "Send message: %p",
				 msg->data);
			ipc_request_sync_int(IPC_MSG_TYPE_MESSAGE,
					     0, 0, msg->data);
			break;
		case IPC_MESSAGE_FREE:
			pr_debug(LOG_MODULE_MAIN, "Free message: %p",
				 msg->data);
			ipc_request_sync_int(IPC_MSG_TYPE_FREE,
					     0, 0, msg->data);
			break;
	}
	bfree(msg);
}
예제 #6
0
static void
message_viewer_wire_header(message_viewer *mv, const u8 *buffer)
{
    /* 1. get the output stream */
    output_stream *os      = mv->os;


    /* 2. get values of the different sections: QUESTION, ANSWER, AUTHORITY and ADDITIONAL */
    u16 count[4];
    count[0]               = ntohs(MESSAGE_QD(buffer));
    count[1]               = ntohs(MESSAGE_AN(buffer));
    count[2]               = ntohs(MESSAGE_NS(buffer));
    count[3]               = ntohs(MESSAGE_AR(buffer));


    /* 3. add the amount of section resource records into a total */
    message_viewer_resource_record_total_update(mv, count);


    /* 4. get message id */
    u16 id                 = MESSAGE_ID(buffer);


    /* 5. get opcode and rcode.
     *    opcode is needed for for knowing the difference between a regular message and a update message
     */
    u8 opcode              = MESSAGE_OP(buffer);
    opcode               >>= OPCODE_SHIFT;

    u8 rcode               = MESSAGE_RCODE(buffer);

    const char *opcode_txt = get_opcode(opcode);
    const char *status_txt = get_rcode(rcode);

    mv->section_name       = (opcode != OPCODE_UPDATE)? message_section_names : message_section_update_names;


    /* if no view with header then inmediately return,
     * wire axfr has no header information so --> return
     */
    if(mv->view_mode_with & VM_WITH_XFR)
    {
        return;
    }


    /* 6. we have all the information, fill the stream */
    osformat(os, ";; Got answer:\n");
    osformat(os, ";; ->>HEADER<<- opcode: %s, status: %s, id: %hd\n", opcode_txt, status_txt, id);
    osformat(os, ";; flags: ");

    if(MESSAGE_QR(buffer) != 0) osprint(os, "qr ");
    if(MESSAGE_AA(buffer) != 0) osprint(os, "aa ");
    if(MESSAGE_TC(buffer) != 0) osprint(os, "tc ");
    if(MESSAGE_RD(buffer) != 0) osprint(os, "rd ");
    if(MESSAGE_RA(buffer) != 0) osprint(os, "ra ");
    if(MESSAGE_ZF(buffer) != 0) osprint(os, "zf ");
    if(MESSAGE_AD(buffer) != 0) osprint(os, "ad ");
    if(MESSAGE_CD(buffer) != 0) osprint(os, "cd ");

    /* 3. get the names for the presentation */
    char  **count_name;
    count_name             = (opcode != OPCODE_UPDATE)? message_count_names   : message_count_update_names;

    osformat(os, "%s: %hd, %s: %hd, %s: %hd, %s: %hd\n",
             count_name[0], count[0],
             count_name[1], count[1],
             count_name[2], count[2],
             count_name[3], count[3]
    );
}
예제 #7
0
static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
        Button *b = userdata;
        struct input_event ev;
        ssize_t l;

        assert(s);
        assert(fd == b->fd);
        assert(b);

        l = read(b->fd, &ev, sizeof(ev));
        if (l < 0)
                return errno != EAGAIN ? -errno : 0;
        if ((size_t) l < sizeof(ev))
                return -EIO;

        if (ev.type == EV_KEY && ev.value > 0) {

                switch (ev.code) {

                case KEY_POWER:
                case KEY_POWER2:
                        log_struct(LOG_INFO,
                                   "MESSAGE=Power key pressed.",
                                   MESSAGE_ID(SD_MESSAGE_POWER_KEY),
                                   NULL);

                        manager_handle_action(b->manager, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true);
                        break;

                /* The kernel is a bit confused here:

                   KEY_SLEEP   = suspend-to-ram, which everybody else calls "suspend"
                   KEY_SUSPEND = suspend-to-disk, which everybody else calls "hibernate"
                */

                case KEY_SLEEP:
                        log_struct(LOG_INFO,
                                   "MESSAGE=Suspend key pressed.",
                                   MESSAGE_ID(SD_MESSAGE_SUSPEND_KEY),
                                   NULL);

                        manager_handle_action(b->manager, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true);
                        break;

                case KEY_SUSPEND:
                        log_struct(LOG_INFO,
                                   "MESSAGE=Hibernate key pressed.",
                                   MESSAGE_ID(SD_MESSAGE_HIBERNATE_KEY),
                                   NULL);

                        manager_handle_action(b->manager, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true);
                        break;
                }

        } else if (ev.type == EV_SW && ev.value > 0) {

                if (ev.code == SW_LID) {
                        log_struct(LOG_INFO,
                                   "MESSAGE=Lid closed.",
                                   MESSAGE_ID(SD_MESSAGE_LID_CLOSED),
                                   NULL);

                        b->lid_closed = true;
                        button_lid_switch_handle_action(b->manager, true);
                        button_install_check_event_source(b);

                } else if (ev.code == SW_DOCK) {
                        log_struct(LOG_INFO,
                                   "MESSAGE=System docked.",
                                   MESSAGE_ID(SD_MESSAGE_SYSTEM_DOCKED),
                                   NULL);

                        b->docked = true;
                }

        } else if (ev.type == EV_SW && ev.value == 0) {

                if (ev.code == SW_LID) {
                        log_struct(LOG_INFO,
                                   "MESSAGE=Lid opened.",
                                   MESSAGE_ID(SD_MESSAGE_LID_OPENED),
                                   NULL);

                        b->lid_closed = false;
                        b->check_event_source = sd_event_source_unref(b->check_event_source);

                } else if (ev.code == SW_DOCK) {
                        log_struct(LOG_INFO,
                                   "MESSAGE=System undocked.",
                                   MESSAGE_ID(SD_MESSAGE_SYSTEM_UNDOCKED),
                                   NULL);

                        b->docked = false;
                }
        }

        return 0;
}