int main(int argc, char **argv) { SaHpiSessionIdT sid = 0; SaErrorT rc = SA_OK; int retc; rc = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sid, NULL); if(rc != SA_OK) return -1; rc = saHpiDiscover(sid); if (rc != SA_OK) return -1; /* inject an event */ retc = inject_event("simulator"); if (retc != 0) { return -1; } /* sleep so the msg thread gets a chance to process the msg */ g_usleep(100000); saHpiSessionClose(sid); return 0; }
int Monitor::run() { DEBUG("Starting inotify thread for path %s...\n", path.c_str()); int fd = inotify_init1(IN_CLOEXEC); if (fd < 0) { ERROR("Unable to start inotify\n"); return fd; } int wd = inotify_add_watch(fd, path.c_str(), mask); if (wd < 0) { ERROR("Unable to add inotify watch on '%s': %s\n", path.c_str(), strerror(errno)); close(fd); return wd; } DEBUG("Starting watching directory %s\n", path.c_str()); for (;;) { size_t len = sizeof(struct inotify_event) + NAME_MAX + 1; struct inotify_event event; char buf[256]; read(fd, &event, len); if (event.mask & (IN_DELETE_SELF | IN_MOVE_SELF)) { inject_event(false, path.c_str()); break; } sprintf(buf, "%s/%s", path.c_str(), event.name); if (!event_accepted(event)) continue; inject_event(event.mask & (IN_MOVED_TO | IN_CLOSE_WRITE | IN_CREATE), buf); } return 0; }
/** * oHpiInjectEvent * @id: id of handler into which the event will be injected. * @event: pointer to the event to be injected. * @rpte: pointer to the resource to be injected. * @rdrs: pointer to the list of RDRs to be injected along with @resoruce * * @id and @event are required parameters. @rpte is only required if the event * is of RESOURCE type or HOTSWAP type. @rdrs is an optional argument in all * cases and can be NULL. If @rdrs is passed, it will be copied. It is the * responsibility of the caller to clean up the RDRs list once it is used here. * * Returns: SA_OK on success. This call will set the event.Source, rpte.ResourceId, * rpte.ResourceEntity so that the caller knows what the final assigned values were. * For rpte.ResourceEntity, the entity_root configuration parameter for the plugin * is used to complete it. In addition, for each rdr in @rdrs, a Num, RecordId, * and Entity will be assigned. This will also be reflected in the passed @rdrs * list so that the caller can know what the assigned values were. **/ SaErrorT oHpiInjectEvent(oHpiHandlerIdT id, SaHpiEventT *event, SaHpiRptEntryT *rpte, GSList *rdrs) { SaErrorT (*inject_event)(void *hnd, SaHpiEventT *evt, SaHpiRptEntryT *rpte, GSList *rdrs); struct oh_handler *h = NULL; SaErrorT error = SA_OK; if (!id) { dbg("Invalid handler id %d passed",id); return SA_ERR_HPI_INVALID_PARAMS; } else if (!event) { dbg("Invalid NULL event passed"); return SA_ERR_HPI_INVALID_PARAMS; } if (oh_init()) return SA_ERR_HPI_INTERNAL_ERROR; h = oh_get_handler(id); inject_event = h ? h->abi->inject_event : NULL; if (!inject_event) { oh_release_handler(h); return SA_ERR_HPI_INVALID_CMD; } error = inject_event(h->hnd, event, rpte, rdrs); if (error) { dbg("Event injection into handler %d failed", id); } oh_release_handler(h); return error; }