Newer
Older
honey-os / src / userland / hlib / service / events.c
  1. #include <hlib.h>
  2. #include <stdint.h>
  3. #include <syscalls.h>
  4.  
  5. uint32_t createEvent(char *name) {
  6. uintptr_t id = insertString(name);
  7. return syscall(SYS_CREATE_EVENT, id, 0, 0, 0);
  8. }
  9.  
  10. uintptr_t hashString(char *string) {
  11. uintptr_t hash = 0;
  12. for (uintptr_t i = 0; string[i]; i++) {
  13. hash = 257 * hash + string[i];
  14. }
  15. return hash;
  16. }
  17.  
  18. uint32_t getEvent(uint32_t service, char *name) {
  19. uintptr_t id = hashString(name);
  20. return syscall(SYS_GET_EVENT, service, id, 0, 0);
  21. }
  22.  
  23. void fireEvent(uint32_t eventNumber) {
  24. syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0);
  25. }
  26.  
  27. void subscribeEvent(uint32_t service, uint32_t event,
  28. void(handler)(void *, uint32_t)) {
  29. syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0);
  30. }