| 74 | } |
| 75 | |
| 76 | static void receive(const msg_t *const msg, UNUSED const void* userdata) { |
| 77 | switch (MSG_TYPE()) { |
| 78 | case FD_UPD: |
| 79 | read_timer(msg->fd_msg->fd); |
| 80 | /* |
| 81 | * We had no cached location and geoclue client timed out; |
| 82 | * tell other modules an go on dropping location |
| 83 | */ |
| 84 | switch (geoclue_st) { |
| 85 | case GEOCLUE_NONE: |
| 86 | WARN("Failed to init (no geoclue2 present?). Killing module.\n"); |
| 87 | break; |
| 88 | case GEOCLUE_PRESENT: |
| 89 | case GEOCLUE_STARTED: |
| 90 | WARN("Timed out waiting on location provided by Geoclue2. Killing module.\n"); |
| 91 | break; |
| 92 | case GEOCLUE_FAILED: |
| 93 | WARN("Failed to start Geoclue2 client. Killing module.\n"); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | if (state.current_loc.lat == LAT_UNDEFINED || state.current_loc.lon == LON_UNDEFINED) { |
| 98 | publish_location(LAT_UNDEFINED, LON_UNDEFINED, &loc_msg); |
| 99 | } |
| 100 | |
| 101 | // if we came here, just kill ourself |
| 102 | module_deregister((self_t **)&self()); |
| 103 | break; |
| 104 | case LOCATION_REQ: { |
| 105 | loc_upd *l = (loc_upd *)MSG_DATA(); |
| 106 | if (VALIDATE_REQ(l)) { |
| 107 | INFO("New location received: %.2lf, %.2lf.\n", l->new.lat, l->new.lon); |
| 108 | // publish location before storing new location as state.current_loc is sent as "old" parameter |
| 109 | publish_location(l->new.lat, l->new.lon, &loc_msg); |
| 110 | memcpy(&state.current_loc, &l->new, sizeof(loc_t)); |
| 111 | } |
| 112 | break; |
| 113 | } |
| 114 | case SYSTEM_UPD: |
| 115 | if (msg->ps_msg->type == LOOP_STARTED) { |
| 116 | load_cache_location(); |
| 117 | if (geoclue_init() != 0) { |
| 118 | /* |
| 119 | * no cached location present and no geoclue; |
| 120 | * fire immediately to take care of module cleanup and deregister |
| 121 | */ |
| 122 | fail_geoclue(GEOCLUE_NONE); |
| 123 | } else { |
| 124 | geoclue_st = GEOCLUE_PRESENT; |
| 125 | } |
| 126 | } else if (msg->ps_msg->type == LOOP_STOPPED) { |
| 127 | cache_location(); |
| 128 | } |
| 129 | break; |
| 130 | default: |
| 131 | break; |
| 132 | } |
| 133 | } |
nothing calls this directly
no test coverage detected