Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUINewsFeed Class Reference

Periodically fetches an RSS feed with news about upcoming releases. More...

#include <GUINewsFeed.h>

Inheritance diagram for GUINewsFeed:
[legend]
Collaboration diagram for GUINewsFeed:
[legend]

Data Structures

struct  Item
 a single entry of the feed More...
 

Public Types

enum  { ID_FETCHED = 1 , ID_SHOW , ID_LAST }
 message ids More...
 

Public Member Functions

time_t getLastAccess () const
 time of the last successful access (0 if never)
 
 GUINewsFeed (FXApp *app, FXWindow *owner, FXStatusBar *statusBar, const std::string &url=DEFAULT_URL)
 constructor
 
long onCmdShow (FXObject *, FXSelector, void *)
 called when the news button was clicked, shows the latest items
 
long onFetched (FXObject *, FXSelector, void *)
 called in the GUI thread when the download has finished
 
void showLatest ()
 shows the latest items, downloading them first if necessary
 
bool startCheck (const bool force=false)
 starts a download if enabled, curl is available and the last access is long enough ago
 
 ~GUINewsFeed ()
 destructor, aborts a running download
 

Static Public Member Functions

static std::vector< Item > parseRSS (const std::string &xml)
 extracts the items of an RSS document
 

Static Public Attributes

static const std::string DEFAULT_URL = "https://eclipse.dev/sumo/feed/news.xml"
 default feed location
 
static const time_t MIN_INTERVAL = 30 * 24 * 60 * 60
 minimum time between two accesses (seconds)
 

Private Member Functions

void fetch ()
 the download, executed in myThread
 
 GUINewsFeed (const GUINewsFeed &)=delete
 invalidated copy constructor
 
GUINewsFeed & operator= (const GUINewsFeed &)=delete
 invalidated assignment operator
 

Private Attributes

std::atomic< bool > myAbort
 tells the worker thread to give up
 
FXApp * myApp = nullptr
 the application (registry access)
 
FXButton * myButton = nullptr
 the button in the status bar (null while there is nothing new)
 
std::string myDocument
 the downloaded document
 
std::vector< Item > myItems
 the latest items (empty until a download succeeded)
 
std::mutex myMutex
 protects myDocument and myOK
 
bool myOK = false
 whether the download succeeded
 
FXWindow * myOwner = nullptr
 parent of the news dialog
 
time_t myPreviousAccess = 0
 the last access time before this download started
 
bool myShowAfterFetch = false
 whether the dialog should open as soon as the running download finishes
 
FXStatusBar * myStatusBar = nullptr
 the status bar holding the news button
 
std::thread myThread
 the worker thread
 
FXEX::MFXThreadEvent myThreadEvent
 wakes the GUI thread
 
std::string myURL
 the feed address
 

Detailed Description

Periodically fetches an RSS feed with news about upcoming releases.

The download runs in a separate thread, the GUI thread is notified via an MFXThreadEvent. The time of the last successful access is stored in the FOX registry (section "NEWS", key "lastaccess", seconds since the epoch). The automatic check can be disabled by setting "lastaccess" to a time far in the future. Explicit requests via showLatest() always work and do not modify "lastaccess".

Definition at line 47 of file GUINewsFeed.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

message ids

Enumerator
ID_FETCHED 
ID_SHOW 
ID_LAST 

Definition at line 61 of file GUINewsFeed.h.

Constructor & Destructor Documentation

◆ GUINewsFeed() [1/2]

GUINewsFeed::GUINewsFeed ( FXApp *  app,
FXWindow *  owner,
FXStatusBar *  statusBar,
const std::string &  url = DEFAULT_URL 
)

constructor

Parameters
[in]appthe application whose registry is used
[in]ownerthe window used as parent of the news dialog
[in]statusBarthe status bar receiving the news button (if null the dialog is shown directly)
[in]urlthe feed address

Definition at line 151 of file GUINewsFeed.cpp.

◆ ~GUINewsFeed()

GUINewsFeed::~GUINewsFeed ( )

destructor, aborts a running download

Definition at line 161 of file GUINewsFeed.cpp.

References myAbort, and myThread.

◆ GUINewsFeed() [2/2]

GUINewsFeed::GUINewsFeed ( const GUINewsFeed &  )
privatedelete

invalidated copy constructor

Member Function Documentation

◆ fetch()

void GUINewsFeed::fetch ( )
private

the download, executed in myThread

Definition at line 214 of file GUINewsFeed.cpp.

References L, myAbort, myDocument, myMutex, myOK, myThreadEvent, myURL, and FXEX::MFXThreadEvent::signal().

Referenced by startCheck().

Here is the caller graph for this function:

◆ getLastAccess()

time_t GUINewsFeed::getLastAccess ( ) const

time of the last successful access (0 if never)

Definition at line 170 of file GUINewsFeed.cpp.

References myApp, NEWS_REG_SECTION, and StringUtils::toLong().

Referenced by onCmdShow(), and startCheck().

Here is the caller graph for this function:

◆ onCmdShow()

long GUINewsFeed::onCmdShow ( FXObject *  ,
FXSelector  ,
void *   
)

called when the news button was clicked, shows the latest items

Definition at line 351 of file GUINewsFeed.cpp.

References ACCEPT, addRichLine(), GUIDesigns::buildFXButton(), GUIIconSubSys::getIcon(), getLastAccess(), GUIDesignAuxiliarHorizontalFrame, GUIDesignButtonDialog, GUIDesignDialogBox, GUIDesignHorizontalFrame, GUIDesignHorizontalSeparator, GUIDesignScrollWindowFixed, myApp, myButton, myItems, myOwner, myStatusBar, NEWS_DISABLED, NEWS_REG_SECTION, NEWS_WRAP_COLUMNS, SUMO_MINI, TL, toString(), StringUtils::trim(), and wrapLine().

Referenced by FXDEFMAP(), onFetched(), and showLatest().

Here is the caller graph for this function:

◆ onFetched()

long GUINewsFeed::onFetched ( FXObject *  ,
FXSelector  ,
void *   
)

called in the GUI thread when the download has finished

Definition at line 259 of file GUINewsFeed.cpp.

References GUIDesigns::buildFXButton(), GUIIconSubSys::getIcon(), ID_SHOW, myApp, myButton, myDocument, myItems, myMutex, myOK, myOwner, myPreviousAccess, myShowAfterFetch, myStatusBar, myThread, NEWS, NEWS_MAX_SHOWN, NEWS_REG_SECTION, onCmdShow(), parseRSS(), TL, and toString().

Referenced by FXDEFMAP().

Here is the caller graph for this function:

◆ operator=()

GUINewsFeed & GUINewsFeed::operator= ( const GUINewsFeed &  )
privatedelete

invalidated assignment operator

◆ parseRSS()

std::vector< GUINewsFeed::Item > GUINewsFeed::parseRSS ( const std::string &  xml)
static

extracts the items of an RSS document

Definition at line 420 of file GUINewsFeed.cpp.

References GUINewsFeed::Item::description, getElement(), GUINewsFeed::Item::link, parseDate(), GUINewsFeed::Item::published, and GUINewsFeed::Item::title.

Referenced by onFetched().

Here is the caller graph for this function:

◆ showLatest()

void GUINewsFeed::showLatest ( )

shows the latest items, downloading them first if necessary

Definition at line 181 of file GUINewsFeed.cpp.

References myItems, myOwner, myShowAfterFetch, myThread, onCmdShow(), startCheck(), and TL.

Referenced by GUIMainWindow::onCmdNews().

Here is the caller graph for this function:

◆ startCheck()

bool GUINewsFeed::startCheck ( const bool  force = false)

starts a download if enabled, curl is available and the last access is long enough ago

Returns
whether a download was started

Definition at line 193 of file GUINewsFeed.cpp.

References fetch(), getLastAccess(), MIN_INTERVAL, myPreviousAccess, myShowAfterFetch, and myThread.

Referenced by GUIMainWindow::checkNews(), and showLatest().

Here is the caller graph for this function:

Field Documentation

◆ DEFAULT_URL

const std::string GUINewsFeed::DEFAULT_URL = "https://eclipse.dev/sumo/feed/news.xml"
static

default feed location

Definition at line 68 of file GUINewsFeed.h.

◆ MIN_INTERVAL

const time_t GUINewsFeed::MIN_INTERVAL = 30 * 24 * 60 * 60
static

minimum time between two accesses (seconds)

Definition at line 71 of file GUINewsFeed.h.

Referenced by startCheck().

◆ myAbort

std::atomic<bool> GUINewsFeed::myAbort
private

tells the worker thread to give up

Definition at line 136 of file GUINewsFeed.h.

Referenced by fetch(), and ~GUINewsFeed().

◆ myApp

FXApp* GUINewsFeed::myApp = nullptr
private

the application (registry access)

Definition at line 112 of file GUINewsFeed.h.

Referenced by getLastAccess(), onCmdShow(), and onFetched().

◆ myButton

FXButton* GUINewsFeed::myButton = nullptr
private

the button in the status bar (null while there is nothing new)

Definition at line 121 of file GUINewsFeed.h.

Referenced by onCmdShow(), and onFetched().

◆ myDocument

std::string GUINewsFeed::myDocument
private

the downloaded document

Definition at line 145 of file GUINewsFeed.h.

Referenced by fetch(), and onFetched().

◆ myItems

std::vector<Item> GUINewsFeed::myItems
private

the latest items (empty until a download succeeded)

Definition at line 124 of file GUINewsFeed.h.

Referenced by onCmdShow(), onFetched(), and showLatest().

◆ myMutex

std::mutex GUINewsFeed::myMutex
private

protects myDocument and myOK

Definition at line 142 of file GUINewsFeed.h.

Referenced by fetch(), and onFetched().

◆ myOK

bool GUINewsFeed::myOK = false
private

whether the download succeeded

Definition at line 148 of file GUINewsFeed.h.

Referenced by fetch(), and onFetched().

◆ myOwner

FXWindow* GUINewsFeed::myOwner = nullptr
private

parent of the news dialog

Definition at line 115 of file GUINewsFeed.h.

Referenced by onCmdShow(), onFetched(), and showLatest().

◆ myPreviousAccess

time_t GUINewsFeed::myPreviousAccess = 0
private

the last access time before this download started

Definition at line 151 of file GUINewsFeed.h.

Referenced by onFetched(), and startCheck().

◆ myShowAfterFetch

bool GUINewsFeed::myShowAfterFetch = false
private

whether the dialog should open as soon as the running download finishes

Definition at line 127 of file GUINewsFeed.h.

Referenced by onFetched(), showLatest(), and startCheck().

◆ myStatusBar

FXStatusBar* GUINewsFeed::myStatusBar = nullptr
private

the status bar holding the news button

Definition at line 118 of file GUINewsFeed.h.

Referenced by onCmdShow(), and onFetched().

◆ myThread

std::thread GUINewsFeed::myThread
private

the worker thread

Definition at line 133 of file GUINewsFeed.h.

Referenced by onFetched(), showLatest(), startCheck(), and ~GUINewsFeed().

◆ myThreadEvent

FXEX::MFXThreadEvent GUINewsFeed::myThreadEvent
private

wakes the GUI thread

Definition at line 139 of file GUINewsFeed.h.

Referenced by fetch().

◆ myURL

std::string GUINewsFeed::myURL
private

the feed address

Definition at line 130 of file GUINewsFeed.h.

Referenced by fetch().


The documentation for this class was generated from the following files: