MicrofeedFeed is thread-aware, because it implements internal lock. Usually an MicrofeedFeed object is accessed simultaneously from multiple threads, for example from a feed update thread and from the main thread responding to DBus messages. When one thread is accessing the object, others are waiting.
Note that MicrofeedFeed launches a new thread for every update and similar operation that may take some time. Thus, you have to call microfeed_thread_init at the very first and microfeed_thread_cleanup at the very last in your application.
typedef struct _MicrofeedFeed MicrofeedFeed |
typedef void(* MicrofeedFeedDestroyCallback)(MicrofeedFeed *feed, void *user_data) |
Definition at line 44 of file microfeedfeed.h.
typedef MicrofeedError*(* MicrofeedFeedDownloadItemDataCallback)(MicrofeedFeed *feed, const char *uid, void **data, size_t *length, void *user_data) |
Definition at line 62 of file microfeedfeed.h.
typedef struct _MicrofeedFeedIterator MicrofeedFeedIterator |
Opaque data type representing Microfeed feed iterator that iterates over the items of the feed.
Definition at line 29 of file microfeedfeed.h.
typedef MicrofeedError*(* MicrofeedFeedModifyItemCallback)(MicrofeedFeed *feed, MicrofeedItem *existing_item, MicrofeedItem *new_item, void *user_data) |
Definition at line 61 of file microfeedfeed.h.
typedef MicrofeedError*(* MicrofeedFeedUpdateCallback)(MicrofeedFeed *feed, int user_initiated, void *user_data) |
This function is called when a subscriber wants to update the feed.
The actual network operations are happening here. The function is called in a separate thread, so it may also block. For pull-type services, typically one update cycle is implemented. For push-type services, this function initializes the connection and waits for the events indefinitely. However, the function must check peridiocally if the subscriber count (microfeed_feed_get_subscriber_count) has dropped to zero and in that case close the connection and return.
The update thread has one reference to the feed meaning that the feed is not freed before the thread finishes. The reference count is incremented and decremented automatically.
If this function returns non-NULL error object, a signal to subscribers is sent.
Definition at line 60 of file microfeedfeed.h.
void microfeed_feed_add_new_setting | ( | MicrofeedFeed * | feed, | |
const char * | uid, | |||
time_t | position, | |||
const char * | text, | |||
const char * | unit, | |||
const char * | type, | |||
const char * | value | |||
) |
Definition at line 522 of file microfeedfeed.c.
References microfeed_feed_replace_item(), microfeed_item_free(), microfeed_item_new(), and microfeed_item_set_property().
void microfeed_feed_add_subscriber | ( | MicrofeedFeed * | feed, | |
const char * | bus_name | |||
) |
Definition at line 288 of file microfeedfeed.c.
References microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, _MicrofeedFeed::reference_count, and _MicrofeedFeed::subscriber_count.
Referenced by microfeed_publisher_new().
void microfeed_feed_free | ( | MicrofeedFeed * | feed | ) |
Definition at line 107 of file microfeedfeed.c.
References _MicrofeedFeed::callbacks, _MicrofeedFeed::database, MicrofeedFeedCallbacks::destroy, _MicrofeedFeedIterator::feed, _MicrofeedFeed::item_data_database, _MicrofeedFeed::iterators, microfeed_database_unref(), microfeed_mutex_free(), microfeed_weak_reference_invalidate(), _MicrofeedFeed::mutex, _MicrofeedFeedIterator::next, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, _MicrofeedFeed::subscriber_count, MicrofeedFeedCallbacks::update, _MicrofeedFeed::uri, _MicrofeedFeed::user_data, and _MicrofeedFeed::weak_reference.
Referenced by microfeed_feed_remove_subscriber(), and microfeed_feed_unref().
MicrofeedItem* microfeed_feed_get_item | ( | MicrofeedFeed * | feed, | |
const char * | uid | |||
) |
Definition at line 309 of file microfeedfeed.c.
References _MicrofeedFeed::database_index, microfeed_database_index_get_data(), microfeed_item_demarshal_properties(), microfeed_item_new(), microfeed_mutex_lock(), microfeed_mutex_unlock(), and _MicrofeedFeed::mutex.
Referenced by microfeed_publisher_add_setting(), microfeed_publisher_get_setting_value(), microfeed_publisher_get_setting_value_integer(), and microfeed_publisher_set_setting_value().
MicrofeedPublisher* microfeed_feed_get_publisher | ( | MicrofeedFeed * | feed | ) |
int microfeed_feed_get_subscriber_count | ( | MicrofeedFeed * | feed | ) |
Definition at line 297 of file microfeedfeed.c.
References microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, and _MicrofeedFeed::subscriber_count.
Referenced by microfeed_publisher_remove_subscriber().
const char* microfeed_feed_get_uri | ( | MicrofeedFeed * | feed | ) |
Definition at line 333 of file microfeedfeed.c.
References _MicrofeedFeed::uri.
Referenced by microfeed_publisher_new().
MicrofeedWeakReference* microfeed_feed_get_weak_reference | ( | MicrofeedFeed * | feed | ) |
Definition at line 161 of file microfeedfeed.c.
References microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_weak_reference_new(), _MicrofeedFeed::mutex, and _MicrofeedFeed::weak_reference.
int microfeed_feed_is_using_threads | ( | MicrofeedFeed * | feed | ) |
MicrofeedFeedIterator* microfeed_feed_iterate | ( | MicrofeedFeed * | feed, | |
const char * | start_uid, | |||
int | backwards | |||
) |
Definition at line 338 of file microfeedfeed.c.
References _MicrofeedFeedIterator::backwards, _MicrofeedFeed::database_index, _MicrofeedFeedIterator::database_iterator, _MicrofeedFeedIterator::feed, _MicrofeedFeed::iterators, microfeed_database_index_iterate(), microfeed_memory_allocate, microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, _MicrofeedFeedIterator::next, _MicrofeedFeedIterator::previous, and _MicrofeedFeedIterator::timeline.
MicrofeedFeedIterator* microfeed_feed_iterate_timeline | ( | MicrofeedFeed * | feed, | |
time_t | start_timestamp, | |||
int | backwards | |||
) |
Definition at line 363 of file microfeedfeed.c.
References _MicrofeedFeedIterator::backwards, _MicrofeedFeed::database, _MicrofeedFeedIterator::database_iterator, _MicrofeedFeedIterator::feed, _MicrofeedFeed::iterators, microfeed_database_iterate(), microfeed_memory_allocate, microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, _MicrofeedFeedIterator::next, _MicrofeedFeedIterator::previous, and _MicrofeedFeedIterator::timeline.
void microfeed_feed_iterator_free | ( | MicrofeedFeedIterator * | iterator | ) |
Definition at line 636 of file microfeedfeed.c.
References _MicrofeedFeedIterator::database_iterator, _MicrofeedFeedIterator::feed, _MicrofeedFeed::iterators, microfeed_database_iterator_free(), microfeed_memory_free(), _MicrofeedFeedIterator::next, and _MicrofeedFeedIterator::previous.
MicrofeedFeed* microfeed_feed_iterator_get_feed | ( | MicrofeedFeedIterator * | iterator | ) |
MicrofeedItem* microfeed_feed_iterator_get_item | ( | MicrofeedFeedIterator * | iterator | ) |
Definition at line 656 of file microfeedfeed.c.
References _MicrofeedFeedIterator::database_iterator, _MicrofeedFeedIterator::feed, microfeed_database_iterator_get(), microfeed_item_demarshal_properties(), microfeed_item_new(), microfeed_mutex_lock(), microfeed_mutex_unlock(), and _MicrofeedFeed::mutex.
int microfeed_feed_iterator_jump_and_remove_previous_items | ( | MicrofeedFeedIterator * | iterator, | |
const char * | uid | |||
) |
Definition at line 683 of file microfeedfeed.c.
References _MicrofeedFeedIterator::backwards, _MicrofeedFeed::database, _MicrofeedFeed::database_index, _MicrofeedFeedIterator::database_iterator, _MicrofeedFeedIterator::feed, microfeed_database_index_get_data(), microfeed_database_index_remove_data_range(), microfeed_database_iterator_get(), microfeed_database_iterator_next(), microfeed_database_remove_data_range(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_send_item_uid_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, _MicrofeedFeedIterator::timeline, and _MicrofeedFeed::uri.
void microfeed_feed_iterator_next | ( | MicrofeedFeedIterator * | iterator | ) |
Definition at line 679 of file microfeedfeed.c.
References _MicrofeedFeedIterator::database_iterator, and microfeed_database_iterator_next().
MicrofeedFeed* microfeed_feed_new | ( | MicrofeedPublisher * | publisher, | |
const char * | uri, | |||
MicrofeedFeedCallbacks * | callbacks, | |||
void * | user_data | |||
) |
Definition at line 75 of file microfeedfeed.c.
References _MicrofeedFeed::callbacks, _MicrofeedFeed::database, _MicrofeedFeed::database_index, MicrofeedFeedCallbacks::download_item_data, _MicrofeedFeed::item_data_database, _MicrofeedFeed::iterators, microfeed_database_environment_get_database(), microfeed_database_get_index(), microfeed_memory_allocate, microfeed_mutex_new(), microfeed_publisher_get_database_environment(), microfeed_store_new_sorted(), microfeed_util_string_concatenate(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::reference_count, _MicrofeedFeed::send_item_data_datas, _MicrofeedFeed::statuses_database, _MicrofeedFeed::uri, _MicrofeedFeed::user_data, and _MicrofeedFeed::weak_reference.
Referenced by microfeed_publisher_new().
MicrofeedFeed* microfeed_feed_ref | ( | MicrofeedFeed * | feed | ) |
Definition at line 138 of file microfeedfeed.c.
References microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, and _MicrofeedFeed::reference_count.
void microfeed_feed_ref_item_data | ( | MicrofeedFeed * | feed, | |
const char * | uid | |||
) |
Definition at line 571 of file microfeedfeed.c.
References _MicrofeedFeed::database, _MicrofeedFeed::item_data_database, microfeed_database_get_data_partial(), microfeed_database_replace_data(), microfeed_database_replace_data_partial(), microfeed_item_get_timestamp(), microfeed_item_marshal_properties(), microfeed_item_new(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_send_item_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, and _MicrofeedFeed::uri.
Referenced by microfeed_publisher_handle_item_property_change().
void microfeed_feed_remove_item | ( | MicrofeedFeed * | feed, | |
const char * | uid | |||
) |
Definition at line 256 of file microfeedfeed.c.
References _MicrofeedFeed::database_index, _MicrofeedFeed::item_data_database, microfeed_database_index_get_data(), microfeed_database_index_remove_data(), microfeed_database_remove_data(), microfeed_item_demarshal_properties(), microfeed_item_free(), microfeed_item_new(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_handle_item_property_change(), microfeed_publisher_send_item_uid_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, and _MicrofeedFeed::uri.
Referenced by microfeed_publisher_remove_setting().
void microfeed_feed_remove_subscriber | ( | MicrofeedFeed * | feed, | |
const char * | bus_name | |||
) |
Definition at line 397 of file microfeedfeed.c.
References microfeed_feed_free(), microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, _MicrofeedFeed::reference_count, and _MicrofeedFeed::subscriber_count.
Referenced by microfeed_publisher_remove_subscriber().
void microfeed_feed_replace_item | ( | MicrofeedFeed * | feed, | |
MicrofeedItem * | item | |||
) |
Definition at line 189 of file microfeedfeed.c.
References _MicrofeedFeed::database, _MicrofeedFeed::database_index, microfeed_database_get_data(), microfeed_database_index_get_data(), microfeed_database_index_remove_data(), microfeed_database_replace_data(), microfeed_item_demarshal_properties(), microfeed_item_free(), microfeed_item_get_timestamp(), microfeed_item_get_uid(), microfeed_item_marshal_properties(), microfeed_item_new(), MICROFEED_ITEM_STATUS_ACTIVE, MICROFEED_ITEM_STATUS_ALL, MICROFEED_ITEM_STATUS_NONE, microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_handle_item_property_change(), microfeed_publisher_send_item_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, and _MicrofeedFeed::uri.
Referenced by microfeed_feed_add_new_setting(), microfeed_publisher_add_setting(), and microfeed_publisher_set_setting_value().
void microfeed_feed_republish | ( | MicrofeedFeed * | feed, | |
const char * | start_uid, | |||
const char * | end_uid, | |||
unsigned int | max_count, | |||
const char * | bus_name | |||
) |
Definition at line 449 of file microfeedfeed.c.
References RepublishingData::bus_name, RepublishingData::end_uid, RepublishingData::feed, RepublishingData::max_count, microfeed_memory_allocate, microfeed_publisher_queue_thread(), _MicrofeedFeed::publisher, and RepublishingData::start_uid.
void microfeed_feed_send_item_data | ( | MicrofeedFeed * | feed, | |
const char * | uid, | |||
const char * | bus_name | |||
) |
Definition at line 534 of file microfeedfeed.c.
References _SendItemDataData::bus_names, _MicrofeedFeed::database_index, _SendItemDataData::feed, _MicrofeedFeed::item_data_database, microfeed_database_get_data(), microfeed_database_index_get_data(), MICROFEED_ERROR_NO_ITEM_DATA, MICROFEED_ERROR_NO_SUCH_ITEM, microfeed_memory_allocate, microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_queue_thread(), microfeed_publisher_send_error_signal(), microfeed_publisher_send_item_data_signal(), microfeed_store_compare_keys_direct(), microfeed_store_get, microfeed_store_get_key_direct(), microfeed_store_insert(), microfeed_store_new_sorted(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::send_item_data_datas, _SendItemDataData::uid, and _MicrofeedFeed::uri.
void microfeed_feed_stop_update | ( | MicrofeedFeed * | feed | ) |
Definition at line 178 of file microfeedfeed.c.
References microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_get_singleton_update_thread(), microfeed_publisher_send_feed_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::updating, and _MicrofeedFeed::uri.
void microfeed_feed_unref | ( | MicrofeedFeed * | feed | ) |
Definition at line 148 of file microfeedfeed.c.
References microfeed_feed_free(), microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedFeed::mutex, and _MicrofeedFeed::reference_count.
Referenced by microfeed_publisher_remove_subscriber().
void microfeed_feed_unref_item_data | ( | MicrofeedFeed * | feed, | |
const char * | uid | |||
) |
Definition at line 610 of file microfeedfeed.c.
References _MicrofeedFeed::database_index, _MicrofeedFeed::item_data_database, microfeed_database_get_data_partial(), microfeed_database_index_remove_data(), microfeed_database_remove_data(), microfeed_database_replace_data_partial(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_send_item_uid_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, and _MicrofeedFeed::uri.
Referenced by microfeed_publisher_handle_item_property_change().
int microfeed_feed_unset_item_status | ( | MicrofeedFeed * | feed, | |
const char * | uid, | |||
MicrofeedItemStatus | status_to_unset | |||
) |
Definition at line 462 of file microfeedfeed.c.
References microfeed_database_get_data(), microfeed_database_remove_data(), microfeed_database_replace_data(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_send_status_changed_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, and _MicrofeedFeed::uri.
void microfeed_feed_unset_item_statuses | ( | MicrofeedFeed * | feed, | |
const char * | start_uid, | |||
const char * | end_uid, | |||
MicrofeedItemStatus | status_to_unset | |||
) |
Definition at line 491 of file microfeedfeed.c.
References microfeed_database_iterate(), microfeed_database_iterator_free(), microfeed_database_iterator_get(), microfeed_database_iterator_next(), microfeed_database_remove_data(), microfeed_database_replace_data(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_send_status_changed_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::statuses_database, and _MicrofeedFeed::uri.
void microfeed_feed_update | ( | MicrofeedFeed * | feed, | |
const char * | bus_name | |||
) |
Definition at line 410 of file microfeedfeed.c.
References _MicrofeedFeed::callbacks, microfeed_error_free(), microfeed_error_get_message(), microfeed_error_get_name(), microfeed_mutex_lock(), microfeed_mutex_unlock(), microfeed_publisher_get_singleton_update_thread(), microfeed_publisher_queue_thread(), microfeed_publisher_send_error_signal(), microfeed_publisher_send_feed_signal(), _MicrofeedFeed::mutex, _MicrofeedFeed::publisher, _MicrofeedFeed::reference_count, MicrofeedFeedCallbacks::update, _MicrofeedFeed::updating, _MicrofeedFeed::uri, and _MicrofeedFeed::user_data.