Author: colin Date: 2010-01-29 21:22:17 +0100 (Fri, 29 Jan 2010) New Revision: 35334 Changeset: http://dev.haiku-os.org/changeset/35334/haiku Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Event.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.h Removed: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Frame.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/FrameResult.h Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Frame.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Jamfile haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Request.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Service.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.cpp haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.h haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Jamfile Log: * Introduced observer and observable interfaces for asynchronous events. * Refactored the authenticate and distribute service to facilitate asynchronous events. * Removed Frame::WaitOnResult(), because frames are never confirmed directly. Instead they are confirmed indirectly by an event != timeout event. Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Event.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Event.h (rev 0) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Event.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -0,0 +1,16 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef IEEE80211_EVENT_H_ +#define IEEE80211_EVENT_H_ + + +namespace Ieee80211 { + +class Event { +}; + +} /* namespace Ieee80211 */ + +#endif /* IEEE80211_EVENT_H_ */ Property changes on: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Event.h ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Frame.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Frame.h 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Frame.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -8,14 +8,10 @@ #include <SupportDefs.h> -#include <FrameResult.h> - namespace Ieee80211 { class Frame { -public: - status_t WaitForResult(FrameResult**); }; } /* namespace Ieee80211 */ Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Jamfile =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Jamfile 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Jamfile 2010-01-29 20:22:17 UTC (rev 35334) @@ -8,12 +8,12 @@ KernelMergeObject ieee80211_stack.o : Device.cpp - Frame.cpp FrameFactory.cpp Stack.cpp : : mac_management.o station_management.o + utilities.o ; HaikuSubInclude mac_management ; Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Request.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Request.h 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Request.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -14,6 +14,7 @@ template<class ResultType> class Request { public: + status_t Confirm(ResultType*); status_t WaitForConfirm(ResultType**); }; @@ -21,6 +22,23 @@ /* #pragma mark - implementation */ +/*! Confirms the request and sets the respective confirmation result. + After successful completion of this method WaitForConfirm() will be + unblocked. + + \param result to be set. + \return B_OK The result was set and WaitForConfirm() was unblocked. + \return Else Neither the result nor unblocking of WaitForConfirm() took + place, due to an unrecoverable error. + */ +template<class ResultType> +status_t +Request<ResultType>::Confirm(ResultType* result) +{ + return B_OK; +} + + /*! Waits until the request was completed. Completion means that the request was either successfully carried out or that there was an error during request-processing. Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Service.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Service.h 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/Service.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -17,7 +17,7 @@ public: virtual status_t Process(ServiceRequest*) = 0; -private: +protected: virtual status_t _Run() = 0; }; Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.cpp 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.cpp 2010-01-29 20:22:17 UTC (rev 35334) @@ -24,7 +24,7 @@ using namespace MacManagement; -// #pragma mark - interface implementation +// #pragma mark - service interface implementation /*! Processes an authenticate request. @@ -41,18 +41,10 @@ if (request == NULL) return B_BAD_VALUE; - AuthenticationFrame* frame = NULL; - status_t status = fFrameFactory.CreateAuthentication(request, &frame); - if (status != B_OK) - return status; - - return fProcessQueue.Enqueue(frame); + return fProcessQueue.Enqueue(request); } -// #pragma mark - private - - /*! Puts the service in its run state. \return B_OK The service terminated gracefully. @@ -62,62 +54,111 @@ AuthenticateService::_Run() { AuthenticationFrame* frame = NULL; - AuthenticateRequestResult* result = NULL; - FrameResult* frameResult = NULL; + AuthenticateRequest* request = NULL; status_t status = B_OK; - + do { - status = fProcessQueue.Dequeue(&frame); + status = fProcessQueue.Dequeue(&request); if (status != B_OK) break; - status = fDistributeService.Process(frame); + status_t status = fFrameFactory.CreateAuthentication(request, &frame); if (status != B_OK) - break; + return status; - status = frame->WaitForResult(&frameResult); + status = fDistributeService.Process(frame); if (status != B_OK) break; - status = _CreateRequestResult(frameResult, &result); - if (status != B_OK) - break; - - status = _ConfirmRequest(frame, result); + status = _WaitForEventAndConfirmRequest(request); } while (status == B_OK); return status; } -// #pragma mark - helper functions +// #pragma mark - observer interface implementation -/*! Completes the pending request belonging to the given frame. +/*! Called by the observed object (the observable) to notify the + AuthenticateService about an event. + Note: Normally only events the AuthenticateService registered for should be + notified here, but this should and will be checked nonetheless. - \param frame used to identify the respective request. - \param result delivered to the request. - \return B_OK The request was confirmed successfully. - \return Else Request wasn't confirmed, due to an unrecoverable error. + \param event which raises execution of this method. + \param observable source of the event. + \result B_OK The event will be processed by the AuthenticateService. + \result Else The event will not be processed by the AuthenticateService. + It shall be safe for the observable to ignore such errors. */ status_t -AuthenticateService::_ConfirmRequest(AuthenticationFrame* frame, - AuthenticateRequestResult* result) +AuthenticateService::NotifyEventFromObservable(Event* event, + Observable* observable) { - return B_OK; + if (event == NULL || observable == NULL) + return B_BAD_VALUE; + + return _IfSupportedEventAndObservableStartProcessing(event, observable); } -/*! Creates an authenticate request result, by using data of the frame result. +/*! Checks, whether the event is one of Class2Error or AuthenticateEven. + */ +bool +AuthenticateService::_IsEventSupported(Event* event) +{ + return true; +} - \param frameResult used to create the authenticate request result. + +/*! Checks, whether the observable is the DistributeService. + */ +bool +AuthenticateService::_IsObservableSupported(Observable* observable) +{ + return observable == &fDistributeService; +} + + +// #pragma mark - private helper functions + + +/*! Creates an authenticate request result, by using data from the event. + + \param event used to create the authenticate request result. \param result used to return the constructed AuthenticateRequestResult. \return B_OK AuthenticateRequestResult constructed successfully. \return Else No result constructed. */ status_t -AuthenticateService::_CreateRequestResult(FrameResult* frameResult, +AuthenticateService::_CreateRequestResult(Event* event, AuthenticateRequestResult** result) { return B_OK; } + + +/*! Waits for any event the AuthenticateService has registered for and confirms + the pending request. + + \param request to be confirmed. + \return B_OK Event received and pending request confirmed. + \return Else request wasn't confirmed, due to an unrecoverable error. + */ +status_t +AuthenticateService::_WaitForEventAndConfirmRequest( + AuthenticateRequest* request) +{ + Event* event = NULL; + AuthenticateRequestResult* result = NULL; + + status_t status = _WaitForEvent(&event); + if (status != B_OK) + return status; + + status = _CreateRequestResult(event, &result); + if (status != B_OK) + return status; + + return request->Confirm(result); +} Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.h 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/AuthenticateService.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -8,33 +8,41 @@ #include <SupportDefs.h> +#include <Event.h> #include <FrameFactory.h> -#include <FrameResult.h> #include <Service.h> #include <mac_management/frames/AuthenticationFrame.h> #include <mac_management/requests/AuthenticateRequest.h> #include <mac_management/results/AuthenticateRequestResult.h> #include <mac_management/services/DistributeService.h> +#include <utilities/Observable.h> +#include <utilities/Observer.h> #include <utilities/Queue.h> namespace Ieee80211 { namespace MacManagement { -class AuthenticateService : public Service<AuthenticateRequest> { +class AuthenticateService + : public Service<AuthenticateRequest>, public Observer { public: virtual status_t Process(AuthenticateRequest*); + virtual status_t NotifyEventFromObservable(Event*, Observable*); + virtual bool _IsEventSupported(Event*); + virtual bool _IsObservableSupported(Observable*); + private: - status_t _ConfirmRequest(AuthenticationFrame*, - AuthenticateRequestResult*); - status_t _CreateRequestResult(FrameResult*, - AuthenticateRequestResult**); virtual status_t _Run(); + status_t _CreateRequestResult(Event*, + AuthenticateRequestResult**); + status_t _WaitForEventAndConfirmRequest( + AuthenticateRequest*); + DistributeService fDistributeService; FrameFactory fFrameFactory; - Queue<AuthenticationFrame> fProcessQueue; + Queue<AuthenticateRequest> fProcessQueue; }; } /* namespace MacManagement */ Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.cpp 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.cpp 2010-01-29 20:22:17 UTC (rev 35334) @@ -21,6 +21,9 @@ using namespace MacManagement; +// #pragma mark - service interface implementation + + /*! Process a frame. Successful return of this method does only mean, that the service3 is going to process the request, not that it was processed already. @@ -46,3 +49,41 @@ { return B_OK; } + + +// #pragma mark - observable interface implementation + + +/*! Register the observer with the event the observer is interested in. + + \param observer to be registered. + \param event the observer is interested in. + \return B_OK The observer was successfully registered with the event. + \return Else The observer wasn't registered, due to an unrecoverable error. + */ +status_t +DistributeService::AddObserverForEvent(Observer* observer, Event* event) +{ + if (observer == NULL || event == NULL) + return B_BAD_VALUE; + + return _IfSupportedObserverAndEventAddThem(observer, event); +} + + +/*! Checks, whether the observer is the AuthenticateServer. + */ +bool +DistributeService::_IsObserverSupported(Observer* observer) +{ + return true; +} + + +/*! Checks, whether the event is one of Class2Error or AuthenticateEven. + */ +bool +DistributeService::_IsEventSupported(Event* event) +{ + return true; +} Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.h 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/mac_management/services/DistributeService.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -10,16 +10,23 @@ #include <Frame.h> #include <Service.h> +#include <utilities/Observable.h> +#include <utilities/Observer.h> namespace Ieee80211 { namespace MacManagement { -class DistributeService : public Service<Frame> { +class DistributeService : public Service<Frame>, public Observable { public: virtual status_t Process(Frame*); + virtual status_t AddObserverForEvent(Observer*, Event*); + private: virtual status_t _Run(); + + virtual bool _IsEventSupported(Event*); + virtual bool _IsObserverSupported(Observer*); }; } /* namespace MacManagement */ } /* namespace Ieee80211 */ Modified: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Jamfile =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Jamfile 2010-01-29 15:54:40 UTC (rev 35333) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Jamfile 2010-01-29 20:22:17 UTC (rev 35334) @@ -1,3 +1,8 @@ SubDir HAIKU_TOP src add-ons kernel network devices ieee80211 stack utilities ; UseHeaders [ FDirName $(SUBDIR) .. ] : true ; + +KernelMergeObject utilities.o : + Observable.cpp + Observer.cpp + ; Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.cpp (rev 0) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.cpp 2010-01-29 20:22:17 UTC (rev 35334) @@ -0,0 +1,32 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Colin Günther, coling@xxxxxx + */ + + +#include <utilities/Observable.h> + + +using namespace Ieee80211; + + +/*! Will register the observer with the event when both are supported by the + observer, only. + + \param observer to be registered. + \param event the observer is interested in. + \return B_OK The observer was successfully registered with the event. + \return Else The observer wasn't registered, due to an unrecoverable error. + */ +status_t +Observable::_IfSupportedObserverAndEventAddThem(Observer* observer, + Event* event) +{ + if (!_IsObserverSupported(observer) && !_IsEventSupported(event)) + return B_BAD_VALUE; + + return B_OK; +} Property changes on: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.h (rev 0) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -0,0 +1,31 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef IEEE80211_OBSERVABLE_H_ +#define IEEE80211_OBSERVABLE_H_ + + +#include <SupportDefs.h> + +#include <Event.h> + + +namespace Ieee80211 { + +class Observer; + +class Observable { +public: + virtual status_t AddObserverForEvent(Observer*, Event*) = 0; + +protected: + virtual bool _IsEventSupported(Event*) = 0; + virtual bool _IsObserverSupported(Observer*) = 0; + + virtual status_t _IfSupportedObserverAndEventAddThem(Observer*, Event*); +}; + +} /* namespace Ieee80211 */ + +#endif /* IEEE80211_OBSERVABLE_H_ */ Property changes on: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observable.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.cpp =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.cpp (rev 0) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.cpp 2010-01-29 20:22:17 UTC (rev 35334) @@ -0,0 +1,53 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Colin Günther, coling@xxxxxx + */ + + +/*! Providing some default implementations for observer interface methods. + */ + + +#include <utilities/Observer.h> + + +using namespace Ieee80211; + + +/*! Will start processing of the event after it was successfully evaluated to be + supported by the observer. + + \param event to be processed. + \param observable to ensure that the event source is an expected one. + \return B_OK Event is supported an will be processed. It doesn't mean that + the event was processed already. As a side-effect the _WaitForEvent() + method will be unblocked. + \return Else The event won't be processed by the observer. + */ +status_t +Observer::_IfSupportedEventAndObservableStartProcessing(Event* event, + Observable* observable) +{ + if (!_IsEventSupported(event) && !_IsObservableSupported(observable)) + return B_BAD_VALUE; + + return fEventQueue.Enqueue(event); +} + + +/*! Waits for an event and returns it afterwards. + Returned events are ensured to be supported by the observer, already. + + \param event to be returned. + \return B_OK An event was received and is safe to use. + \return Else Don't use the event parameter, as there was an unrecoverable + error while waiting. + */ +status_t +Observer::_WaitForEvent(Event** event) +{ + return fEventQueue.Dequeue(event); +} Property changes on: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.h =================================================================== --- haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.h (rev 0) +++ haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.h 2010-01-29 20:22:17 UTC (rev 35334) @@ -0,0 +1,36 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef IEEE80211_OBSERVER_H_ +#define IEEE80211_OBSERVER_H_ + + +#include <SupportDefs.h> + +#include <Event.h> +#include <utilities/Queue.h> + + +namespace Ieee80211 { + +class Observable; + +class Observer { +public: + virtual status_t NotifyEventFromObservable(Event*, Observable*) = 0; + +protected: + virtual bool _IsEventSupported(Event*) = 0; + virtual bool _IsObservableSupported(Observable*) = 0; + virtual status_t _IfSupportedEventAndObservableStartProcessing(Event*, + Observable*); + virtual status_t _WaitForEvent(Event**); + +private: + Queue<Event> fEventQueue; +}; + +} /* namespace Ieee80211 */ + +#endif /* IEEE80211_OBSERVER_H_ */ Property changes on: haiku/branches/developer/colin/wireless/src/add-ons/kernel/network/devices/ieee80211/stack/utilities/Observer.h ___________________________________________________________________ Added: svn:mime-type + text/plain