A new start
Because I have been looking for shortcuts to deal with the problem, I have delayed a lot of time, but it is a bit of a harvest.
Recently, I talked with my tutors about many solutions to my project. This time we adopted a conservative strategy.
First try to get the data of the new log message in the journal, and then add them to the model.
Yes, it doesn’t seem to be a difficult problem. Let’s get started.
First gl-journal.c is to process the underlying data.
static gboolean
on_journal_changed (gint fd,
GIOCondition condition,
GlJournal *self)
{
gint ret;
GlJournalEntry *entry;
GlJournalPrivate *priv = gl_journal_get_instance_private (self);
ret = sd_journal_process (priv->journal);
switch (ret)
{
case SD_JOURNAL_NOP:
g_debug ("Journal change was a no-op");
break;
case SD_JOURNAL_APPEND:
g_debug ("New journal entries added");
break;
Then I should add some code here to make it get new log messages. Before that, I found that in gl-journal. c there will be a signal to send a new message, so it must be added after this. Some code to get a new log. Found _gl_query_jouranl_entry(),
static GlJournalEntry *
_gl_journal_query_entry (GlJournal *self);
this function can be used to organize an entry, because the parameters passed are only self, but according to what standard to organize the entry.
after some experiments, it is finally found that the cursor is located according to the current journal. This has led to a very important concept - the cursor.
imaginary sd_journal* journal. The syslog entry can actually imagine that he is a doubly linked list, because it supports (sd_journal_next(journal), sd_journal_previous), so far, an idea is ready to go, Resolve how to respond to updates
But obviously faced with several problems
- Cursor_last, how to initialize,
- How to add the model after getting the entry, the relevant code for processing the model is defined in gl-journal-model.c.
- How to read when reading data, how to use sd_journal_seek_tail() and gl_journal_previous/next() I don’t understand clearly, because I don’t understand the documentation very clearly.
I will try my best to solve this problem in the next time. Go ahead!