Changeset 28:9b3c2d3ea9f3 in vscpl for src/hu


Ignore:
Timestamp:
12/15/22 15:56:11 (23 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Event object creation is moved into a factory.

Location:
src/hu/varadiistvan/scpl/io/_win32
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/hu/varadiistvan/scpl/io/_win32/BufferedStream.cc

    r9 r28  
    4040//------------------------------------------------------------------------------
    4141
    42 BufferedStream::BufferedStream(Waiter* waiter, HANDLE handle,
     42BufferedStream::BufferedStream(std::unique_ptr<EventFactory> eventFactory,
     43                               Waiter* waiter, HANDLE handle,
    4344                               size_t readingCapacity, size_t writingCapacity) :
    44     Overlappable(waiter, handle),
     45    Overlappable(std::move(eventFactory), waiter, handle),
    4546    readingBuffer( (readingCapacity==0) ? 0 :
    4647                   new ReadingBuffer(readingCapacity, this)),
  • src/hu/varadiistvan/scpl/io/_win32/BufferedStream.h

    r9 r28  
    7676     * Construct the buffered stream.
    7777     */
    78     BufferedStream(Waiter* waiter = 0, HANDLE handle = 0,
     78    BufferedStream(std::unique_ptr<EventFactory> eventFactory,
     79                   Waiter* waiter = 0, HANDLE handle = 0,
    7980                   size_t readingCapacity = DEFAULT_CAPACITY,
    8081                   size_t writingCapacity = DEFAULT_CAPACITY);
  • src/hu/varadiistvan/scpl/io/_win32/Event.h

    r6 r28  
    133133inline Event::Event(EventFailable& eventFailable) :
    134134    eventFailable(eventFailable),
    135     handle(CreateEvent(0, true, false, 0)),
     135    handle(eventFailable.createEvent()),
    136136    waiter(0)
    137137{
     
    144144{
    145145    removeFromWaiter();
    146     CloseHandle(handle);
     146    eventFailable.destroyEvent(handle);
    147147}
    148148
     
    172172inline void Event::fire()
    173173{
    174     if (!SetEvent(handle)) {
     174    if (!eventFailable.setEvent(handle)) {
    175175        eventFailable.setErrorCode(GetLastError());
    176176    }
     
    181181inline bool Event::clear()
    182182{
    183     if (!ResetEvent(handle)) {
     183    if (!eventFailable.resetEvent(handle)) {
    184184        eventFailable.setErrorCode(GetLastError());
    185185        return false;
  • src/hu/varadiistvan/scpl/io/_win32/EventFailable.h

    r6 r28  
    3333#include "../Failable.h"
    3434
     35#include "EventFactory.h"
     36
     37#include <memory>
     38
    3539//------------------------------------------------------------------------------
    3640
     
    5155class EventFailable : public Failable
    5256{
     57protected:
     58    /**
     59     * The event factory for this object.
     60     */
     61    std::unique_ptr<EventFactory> eventFactory;
     62
     63protected:
     64    /**
     65     * Construct the object with the given event factory.
     66     */
     67    EventFailable(std::unique_ptr<EventFactory> eventFactory);
     68
     69    /**
     70     * Create an event for this object using the event factory.
     71     */
     72    HANDLE createEvent();
     73
     74    /**
     75     * Set the event represented by the given handle using the event factory.
     76     */
     77    bool setEvent(HANDLE handle);
     78
     79    /**
     80     * Set the event represented by the given handle using the event factory.
     81     */
     82    bool resetEvent(HANDLE handle);
     83
     84    /**
     85     * Destroy the event represented by the given handle using the event factory.
     86     */
     87    void destroyEvent(HANDLE handle);
     88
    5389    friend class Event;
    5490};
     91
     92//------------------------------------------------------------------------------
     93// Inline definitions
     94//------------------------------------------------------------------------------
     95
     96inline EventFailable::EventFailable(std::unique_ptr<EventFactory> eventFactory) :
     97    eventFactory(std::move(eventFactory))
     98{
     99}
     100
     101//------------------------------------------------------------------------------
     102
     103inline HANDLE EventFailable::createEvent()
     104{
     105    return eventFactory->createEvent();
     106}
     107
     108//------------------------------------------------------------------------------
     109
     110inline bool EventFailable::setEvent(HANDLE handle)
     111{
     112    return eventFactory->setEvent(handle);
     113}
     114
     115//------------------------------------------------------------------------------
     116
     117inline bool EventFailable::resetEvent(HANDLE handle)
     118{
     119    return eventFactory->resetEvent(handle);
     120}
     121
     122//------------------------------------------------------------------------------
     123
     124inline void EventFailable::destroyEvent(HANDLE handle)
     125{
     126    eventFactory->destroyEvent(handle);
     127}
    55128
    56129//------------------------------------------------------------------------------
  • src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.h

    r9 r28  
    8383
    8484inline LocalServerSocketBase::LocalServerSocketBase(Waiter* waiter) :
    85     Overlappable(waiter)
     85    Overlappable(std::make_unique<EventFactory>(), waiter)
    8686{
    8787}
  • src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h

    r14 r28  
    8989inline LocalSocket::LocalSocket(Waiter* waiter, HANDLE handle,
    9090                                size_t readingCapacity, size_t writingCapacity):
    91     BufferedStream(waiter, handle, readingCapacity, writingCapacity)
     91    BufferedStream(std::make_unique<EventFactory>(),
     92                   waiter, handle, readingCapacity, writingCapacity)
    9293{
    9394}
  • src/hu/varadiistvan/scpl/io/_win32/Makefile.am

    r25 r28  
    77libvscpl_io_win32_la_SOURCES=\
    88        Event.cc                \
     9        EventFactory.cc         \
    910        Overlapped.cc           \
    1011        Waiter.cc               \
     
    1819include_vscpl_io_win32dir=$(includedir)/hu/varadiistvan/scpl/io/_win32
    1920include_vscpl_io_win32_HEADERS=\
     21        EventFactory.h          \
    2022        EventFailable.h         \
    2123        Overlappable.h          \
  • src/hu/varadiistvan/scpl/io/_win32/Overlappable.h

    r9 r28  
    6767     * Construct the object.
    6868     */
    69     Overlappable(Waiter* waiter = 0, HANDLE handle = 0);
     69    Overlappable(std::unique_ptr<EventFactory> eventFactory,
     70                 Waiter* waiter = 0, HANDLE handle = 0);
    7071
    7172public:
     
    9798//------------------------------------------------------------------------------
    9899
    99 inline Overlappable::Overlappable(Waiter* waiter, HANDLE handle) :
     100inline Overlappable::Overlappable(std::unique_ptr<EventFactory> eventFactory,
     101                                  Waiter* waiter, HANDLE handle) :
     102    EventFailable(std::move(eventFactory)),
    100103    waiter(waiter),
    101104    handle(handle)
  • src/hu/varadiistvan/scpl/io/_win32/WaitableEvent.h

    r7 r28  
    4141 * An event which can be waited for.
    4242 */
    43 class WaitableEvent : public Event, public EventFailable
     43class WaitableEvent : public EventFailable, public Event
    4444{
    4545public:
     
    6161
    6262inline WaitableEvent::WaitableEvent(Waiter* waiter) :
     63    EventFailable(std::make_unique<EventFactory>()),
    6364    Event(static_cast<EventFailable&>(*this))
    6465{
Note: See TracChangeset for help on using the changeset viewer.