view Platforms/Wasm/WasmDelayedCallExecutor.h @ 973:38409549db43 toa2019082903

Log with addresses + added fingerprint mechanism to avoid calling zombie objects where: - a message is sent with a receiver - the receiver dies - another receiver with the SAME address is created - the message reply is executed --> execution on the wrong object! (since their "identity" is their address. The fix is to identify them with an UUID stored at creation time)
author Benjamin Golinvaux <bgo@osimis.io>
date Thu, 29 Aug 2019 18:07:55 +0200
parents c35e98d22764
children
line wrap: on
line source

#pragma once

#include "../../Framework/Deprecated/Toolbox/IDelayedCallExecutor.h"
#include <Core/OrthancException.h>

namespace Deprecated
{
  class WasmDelayedCallExecutor : public IDelayedCallExecutor
  {
  private:
    static OrthancStone::MessageBroker* broker_;

    // Private constructor => Singleton design pattern
    WasmDelayedCallExecutor(OrthancStone::MessageBroker& broker) :
      IDelayedCallExecutor(broker)
    {
    }

  public:
    static WasmDelayedCallExecutor& GetInstance()
    {
      if (broker_ == NULL)
      {
        printf("WasmDelayedCallExecutor::GetInstance(): broker not initialized\n");
        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
      }
      static WasmDelayedCallExecutor instance(*broker_);
      return instance;
    }

    static void SetBroker(OrthancStone::MessageBroker& broker)
    {
      broker_ = &broker;
    }

    virtual void Schedule(OrthancStone::MessageHandler<IDelayedCallExecutor::TimeoutMessage>* callback,
                         unsigned int timeoutInMs = 1000);

  };
}