std::string IDSEXT::RegisterProvider(const std::string& providerName)
{
    Json::FastWriter writer;
    Json::Value resultJSON;

    ids_provider_mapping *registeredItem = reinterpret_cast<ids_provider_mapping *>(malloc(sizeof(ids_provider_mapping)));
    if (!registeredItem) {
        fprintf(stderr, "Unable to register IDS provider - malloc error\n");
        return "";
    }

    registeredItem->providerName = strdup(providerName.c_str());
    resultJSON["result"] = ids_register_provider(registeredItem->providerName, &registeredItem->provider, &registeredItem->providerFd);
    if ( (ids_result_t) resultJSON["result"].asInt() == IDS_SUCCESS ) {
        registeredItem->next = providers;
        providers = registeredItem;

        registeredItem->sigEvent = new sigevent;
        registeredItem->sigEvent->sigev_notify = SIGEV_PULSE;
        registeredItem->sigEvent->sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0, eventCHID, _NTO_SIDE_CHANNEL, 0);
        registeredItem->sigEvent->sigev_priority = getprio(0);
        registeredItem->sigEvent->sigev_code = registeredItem->providerFd;
        registeredItem->sigEvent->sigev_value.sival_int = registeredItem->providerFd;

        if (ionotify(registeredItem->providerFd, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT, registeredItem->sigEvent) & _NOTIFY_COND_INPUT) {
            MsgDeliverEvent(0, registeredItem->sigEvent);
        }
    } else {
        resultJSON["errno"] = strerror(errno);
    }

    std::string resultStr = writer.write(resultJSON);
    return( resultStr.c_str() );
}
void* IDSEXT::idsEventThread(void *args)
{
    IDSEXT *idsExt = reinterpret_cast<IDSEXT *>(args);

    struct _pulse msg;

    eventCHID = ChannelCreate(_NTO_CHF_COID_DISCONNECT);

    while ( idsExt->connected ) {
        if (MsgReceive(eventCHID, &msg, sizeof(msg), NULL) == 0) {
            // Find provider - process msg
            ids_provider_mapping* current = idsExt->providers;

            while ( current != NULL ) {
                if ( msg.code == current->providerFd ) {
                    // Re-arm ionotify
                    if (ids_process_msg(current->providerFd) != IDS_SUCCESS) {
                        fprintf(stderr, "Failed to process IDS message\n");
                        idsExt->removeProvider(current->providerFd);
                    } else {
                        if (ionotify(current->providerFd, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT, current->sigEvent) & _NOTIFY_COND_INPUT) {
                            MsgDeliverEvent(0, current->sigEvent);
                        }
                    }
                }
                current = current->next;
            }
        }
    }

    pthread_detach(pthread_self());
    return NULL;
}
Esempio n. 3
0
int mq_notify(mqd_t mq, const struct sigevent *event) {
	int rc;
	struct sigevent	tmp;

	if(event && SIGEV_GET_TYPE(event) == SIGEV_SIGNAL) {
		tmp = *event;
		tmp.sigev_notify = SIGEV_SIGNAL_CODE;
		tmp.sigev_code = SI_MESGQ;
		event = &tmp;
	}

	if (((rc = ionotify(mq, _NOTIFY_ACTION_TRANARM,
		_NOTIFY_COND_INPUT, event)) == -1) && (errno == EAGAIN)) {
		rc = 0;
	}

	return((rc == -1) ? __mq_check(!0, mq) : 0);
}