Bläddra i källkod

faux.sched: Function to get entry by ID

Serj Kalichev 3 år sedan
förälder
incheckning
c58ff62ecd
2 ändrade filer med 54 tillägg och 0 borttagningar
  1. 3 0
      faux/sched.h
  2. 51 0
      faux/sched/sched.c

+ 3 - 0
faux/sched.h

@@ -43,6 +43,9 @@ int faux_sched_pop(faux_sched_t *sched, int *ev_id, void **data);
 int faux_sched_remove_by_id(faux_sched_t *sched, int id);
 int faux_sched_remove_by_data(faux_sched_t *sched, void *data);
 const struct timespec *faux_sched_time_by_data(faux_sched_t *sched, void *data);
+bool_t faux_sched_id_exist(faux_sched_t *sched, int id);
+bool_t faux_sched_get_by_id(faux_sched_t *sched, int ev_id, void **data,
+	faux_list_node_t **saved);
 
 C_DECL_END
 

+ 51 - 0
faux/sched/sched.c

@@ -296,6 +296,7 @@ int faux_sched_pop(faux_sched_t *sched, int *ev_id, void **data)
 	return 0;
 }
 
+
 /** @brief Removes all events with specified ID from list.
  *
  * @param [in] sched Allocated and initialized sched object.
@@ -348,6 +349,56 @@ int faux_sched_remove_by_data(faux_sched_t *sched, void *data)
 }
 
 
+/** @brief Report does entry with specified ID already exist.
+ *
+ * @param [in] sched Allocated and initialized sched object.
+ * @param [in] id ID.
+ * @return BOOL_TRUE - exist, BOOL_FALSE - doesn't exist.
+ */
+bool_t faux_sched_id_exist(faux_sched_t *sched, int id)
+{
+	assert(sched);
+	if (!sched)
+		return -1;
+
+	if (faux_list_match_node(sched->list, faux_ev_compare_id, &id, NULL))
+		return BOOL_TRUE;
+
+	return BOOL_FALSE;
+}
+
+
+/** @brief Get sched entries with specified ID.
+ *
+ * @param [in] sched Allocated and initialized sched object.
+ * @param [in] id ID to search for.
+ * @param [out] data Return user data.
+ * @param [in,out] saved Iterator.
+ * @return BOOL_TRUE - found, BOOL_FALSE - not found.
+ */
+bool_t faux_sched_get_by_id(faux_sched_t *sched, int ev_id, void **data,
+	faux_list_node_t **saved)
+{
+	faux_list_node_t *node = NULL;
+	faux_ev_t *ev = NULL;
+
+	assert(sched);
+	if (!sched)
+		return BOOL_FALSE;
+
+	node = faux_list_match_node(sched->list,
+		faux_ev_compare_id, &ev_id, saved);
+	if (!node)
+		return BOOL_FALSE;
+
+	ev = (faux_ev_t *)faux_list_data(node);
+	if (data)
+		*data = faux_ev_data(ev);
+
+	return BOOL_TRUE;
+}
+
+
 /** @brief Get time of events with specified data pointer from list.
  *
  * @param [in] sched Allocated and initialized sched object.