XDispatch 0.7.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
source.h
Go to the documentation of this file.
00001 
00002 /*
00003 * Copyright (c) 2011-2013 MLBA-Team. All rights reserved.
00004 *
00005 * @MLBA_OPEN_LICENSE_HEADER_START@
00006 *
00007 * Licensed under the Apache License, Version 2.0 (the "License");
00008 * you may not use this file except in compliance with the License.
00009 * You may obtain a copy of the License at
00010 *
00011 *     http://www.apache.org/licenses/LICENSE-2.0
00012 *
00013 * Unless required by applicable law or agreed to in writing, software
00014 * distributed under the License is distributed on an "AS IS" BASIS,
00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 * See the License for the specific language governing permissions and
00017 * limitations under the License.
00018 *
00019 * @MLBA_OPEN_LICENSE_HEADER_END@
00020 */
00021 
00022 
00023 #ifndef XDISPATCH_SOURCE_H_
00024 #define XDISPATCH_SOURCE_H_
00025 
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034 
00035 #include "any.h"
00036 
00037 __XDISPATCH_BEGIN_NAMESPACE
00038 
00039 class source;
00040 
00041 
00050 class XDISPATCH_EXPORT sourcetype {
00051 
00052     public:
00053             virtual ~sourcetype();
00054 
00055     protected:
00056             sourcetype();
00057 
00064             void ready(const any& = any());
00073             virtual dispatch_source_t native();
00082             virtual void on_cancel();
00092             virtual void on_resume();
00102             virtual void on_suspend();
00116             virtual bool propagate_targetqueue() const { return false; }
00117 
00118     private:
00119             sourcetype(const sourcetype&){}
00120             void set_cb(source*);
00121             friend class source;
00122             source* cb;
00123 };
00124 
00125 
00126 class native_source_wrapper;
00127 
00137 class XDISPATCH_EXPORT native_source : public sourcetype {
00138 
00139     public:
00140         native_source(dispatch_source_t);
00141         ~native_source();
00142 
00143     protected:
00144         virtual dispatch_source_t native();
00145         void on_resume ();
00146         void on_suspend ();
00147         void on_cancel ();
00148         bool propagate_targetqueue () const;
00149 
00155         virtual void on_source_ready();
00156 
00157     private:
00158         pointer<native_source_wrapper>::shared _source;
00159 };
00160 
00161 
00176 class XDISPATCH_EXPORT source : public object {
00177 
00178     public:
00182             source(sourcetype*);
00183             ~source();
00184 
00185             void resume();
00186             void suspend();
00187 
00194             void handler(xdispatch::operation*);
00195     #if XDISPATCH_HAS_BLOCKS
00196 
00202             virtual inline void handler(dispatch_block_t b) {
00203                 handler( new block_operation(b) );
00204             }
00205     #endif
00206     #if XDISPATCH_HAS_FUNCTION
00207 
00213             virtual inline void handler(const lambda_function& b) {
00214                 handler( new function_operation(b) );
00215             }
00216     #endif
00217 
00220             void target_queue(const xdispatch::queue&);
00224             xdispatch::queue target_queue() const;
00237             template <typename T> static T data(){
00238                     return _data()->cast<T>();
00239             }
00240 
00246             virtual dispatch_object_t native() const;
00252             dispatch_source_t native_source() const;
00275             void cancel();
00284             void cancel_handler(xdispatch::operation*);
00285     #if XDISPATCH_HAS_BLOCKS
00286 
00294             virtual inline void cancel_handler(dispatch_block_t b) {
00295                 cancel_handler( new block_operation(b) );
00296             }
00297     #endif
00298     #if XDISPATCH_HAS_FUNCTION
00299 
00307             virtual inline void cancel_handler(const lambda_function& b) {
00308                 cancel_handler( new function_operation(b) );
00309             }
00310     #endif
00311 
00312     private:
00313             source(const source&);
00314             source& operator=(const source&);
00315             class pdata;
00316             pointer<pdata>::shared d;
00317 
00318             void notify(const any&);
00319             sourcetype* source_type();
00320             static const any* _data();
00321             friend class sourcetype;
00322             friend class timer;
00323 };
00324 
00325 __XDISPATCH_END_NAMESPACE
00326 
00329 #endif /* XDISPATCH_SOURCE_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Jan 27 2013 21:21:52 for XDispatch by Doxygen 1.7.6.1
© 2010-2013 MLBA (about | privacy) All Rights reserved.