Changeset c8cb0d for ThirdParty


Ignore:
Timestamp:
Dec 26, 2025, 9:40:14 PM (5 weeks ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.1, stable
Children:
033646
Parents:
f2d5ce
git-author:
Frederik Heber <frederik.heber@…> (12/10/25 16:15:28)
git-committer:
Frederik Heber <frederik.heber@…> (12/26/25 21:40:14)
Message:

Streamlines channel creation in Observables.

  • CodePatterns is now version 1.3.4.
  • we no longer need to add the channels manually in the cstor of a class that derives from Observable. Instead, we just need to pass the maximum number of channels (as they are typically enumerated anyway) and they are generated and added.
  • added mutex protection when inserting.
  • adjusted class Relay to forward similar convenience cstors.
  • adjusted all call sites in molecuilder.
Location:
ThirdParty
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ThirdParty/CodePatterns/configure.ac

    rf2d5ce rc8cb0d  
    33
    44AC_PREREQ([2.65])
    5 AC_INIT([LibCodePatterns], [1.3.3], [heber@ins.uni-bonn.de], [libcodepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/])
     5AC_INIT([LibCodePatterns], [1.3.4], [heber@ins.uni-bonn.de], [libcodepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/])
    66AC_CONFIG_AUX_DIR([build-aux])
    77AC_CONFIG_SRCDIR([src/codepatterns-config-main.cpp])
     
    3939# refer to the libtool manual, section "Updating library version information":
    4040# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
    41 AC_SUBST([CODEPATTERNS_SO_VERSION], [12:2:1])
    42 AC_SUBST([CODEPATTERNS_API_VERSION], [1.3.3])
     41AC_SUBST([CODEPATTERNS_SO_VERSION], [12:3:1])
     42AC_SUBST([CODEPATTERNS_API_VERSION], [1.3.4])
    4343
    4444# Checks for libraries.
  • ThirdParty/CodePatterns/src/CodePatterns/Observer/Observable.hpp

    rf2d5ce rc8cb0d  
    5151  typedef std::vector<size_t> channels_t;
    5252
     53  /** Constructor for class Observable.
     54   */
    5355  Observable(
    5456      std::string _name,
    5557      const channels_t &_channels = channels_t());
     58
     59  /** Convenience cstor which generates a number of notifications
     60   * in channels.
     61   */
     62  Observable(
     63      std::string _name,
     64      const unsigned int _maximum_notification_types);
     65
    5666  virtual ~Observable();
    5767
     
    137147protected:
    138148
    139   static void insertNotificationChannel( std::pair<Observable*, Channels *> _pair);
    140149  static void eraseNotificationChannel(Observable * const _target);
    141150  static bool isNotificationChannelPresent(const Observable * const _target);
     
    143152  static Notification_ptr getNotificationChannel(const Observable * const _target, const size_t _no);
    144153
     154  void createAndInsertNotificationChannel(const unsigned int _maximum_notification_types);
     155
    145156private:
     157  /**
     158   * Private inserter for a notification channel.
     159   *
     160   * Use \a createAndInsertNotificationChannel() instead.
     161   */
     162  static void insertNotificationChannel( std::pair<Observable*, Channels *> _pair);
    146163
    147164  typedef std::map<Observable*, Channels *> ChannelMap;
  • ThirdParty/CodePatterns/src/CodePatterns/Observer/Relay.hpp

    rf2d5ce rc8cb0d  
    3434public:
    3535  Relay(std::string _name);
     36  Relay(std::string _name, const channels_t &_channels);
     37  Relay(std::string _name, const unsigned int _maximum_notification_types);
    3638  virtual ~Relay();
    3739
  • ThirdParty/CodePatterns/src/Observer/Observable.cpp

    rf2d5ce rc8cb0d  
    383383}
    384384
    385 /** Constructor for class Observable.
    386  */
    387385Observable::Observable(
    388386    std::string name,
     
    405403    insertNotificationChannel( std::make_pair(static_cast<Observable *>(this), OurChannel) );
    406404  }
     405}
     406
     407Observable::Observable(
     408    std::string name,
     409    const unsigned int _maximum_notification_types) :
     410  Observer(Observer::BaseConstructor()),
     411  graveyard_informer(&noop_informer)
     412{
     413#ifdef LOG_OBSERVER
     414  observerLog().addName(this,name);
     415  observerLog().addMessage() << "++ Creating Observable "
     416      << observerLog().getName(static_cast<Observable *>(this));
     417#endif
     418  createAndInsertNotificationChannel(_maximum_notification_types);
    407419}
    408420
     
    459471}
    460472
     473void Observable::createAndInsertNotificationChannel(const unsigned int _maximum_notification_types)
     474{
     475  boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex());
     476  Channels *OurChannel = new Channels;
     477  // add instance for each notification type
     478  for (size_t type = 0; type < _maximum_notification_types; ++type)
     479    OurChannel->addChannel(type);
     480  insertNotificationChannel( std::make_pair(static_cast<Observable *>(this), OurChannel) );
     481}
     482
    461483void Observable::eraseNotificationChannel(Observable * const _target)
    462484{
  • ThirdParty/CodePatterns/src/Observer/Relay.cpp

    rf2d5ce rc8cb0d  
    3333Relay::Relay(std::string name) :
    3434  Observable(name),
     35  Updater(NULL)
     36{
     37#ifdef LOG_OBSERVER
     38  observerLog().addName(this,name);
     39  observerLog().addMessage() << "++ Creating Relay " << observerLog().getName(this);
     40#endif
     41}
     42
     43/** Constructor for class Relay.
     44 */
     45Relay::Relay(std::string name, const channels_t &_channels) :
     46  Observable(name, _channels),
     47  Updater(NULL)
     48{
     49#ifdef LOG_OBSERVER
     50  observerLog().addName(this,name);
     51  observerLog().addMessage() << "++ Creating Relay " << observerLog().getName(this);
     52#endif
     53}
     54
     55/** Constructor for class Relay.
     56 */
     57Relay::Relay(std::string name, const unsigned int _maximum_notification_types) :
     58  Observable(name, _maximum_notification_types),
    3559  Updater(NULL)
    3660{
  • ThirdParty/CodePatterns/src/Observer/unittests/stubs/ObserverStub.cpp

    rf2d5ce rc8cb0d  
    133133
    134134NotificationObservable::NotificationObservable() :
    135   Observable("NotificationObservable")
    136 {
    137   Channels *OurChannel = new Channels();
    138   Observable::insertNotificationChannel( std::make_pair(this, OurChannel) );
    139   OurChannel->addChannel(Operation1Notify);
    140   OurChannel->addChannel(Operation2Notify);
    141 }
     135  Observable("NotificationObservable", { Operation1Notify, Operation2Notify })
     136{}
    142137
    143138NotificationObservable::~NotificationObservable()
     
    242237
    243238RelayNotification::RelayNotification() :
    244     Relay(std::string("RelayTest"))
    245 {
    246   Channels *OurChannel = new Channels();
    247   Observable::insertNotificationChannel( std::make_pair(this, OurChannel) );
    248   OurChannel->addChannel(NotificationObservable::Operation1Notify);
    249   OurChannel->addChannel(NotificationObservable::Operation2Notify);
    250 }
     239    Relay(std::string("RelayTest"), { NotificationObservable::Operation1Notify, NotificationObservable::Operation2Notify })
     240{}
    251241
    252242RelayNotification::~RelayNotification()
  • ThirdParty/JobMarket/src/JobMarket/FragmentQueue.cpp

    rf2d5ce rc8cb0d  
    4848 */
    4949FragmentQueue::FragmentQueue() :
    50     Observable("FragmentQueue"),
     50    Observable("FragmentQueue", NotificationType_MAX),
    5151    doneJobs(0)
    52 {
    53   // observable stuff
    54   Channels *OurChannel = new Channels;
    55   Observable::insertNotificationChannel( std::make_pair(static_cast<Observable *>(this), OurChannel) );
    56   // add instance for each notification type
    57   for (size_t type = 0; type < NotificationType_MAX; ++type)
    58     OurChannel->addChannel(type);
    59 }
     52{}
    6053
    6154/** Destructor for class FragmentQueue.
Note: See TracChangeset for help on using the changeset viewer.