Turned timeout into a single implementation style object. Therefore, now it

can be declared as a type timeout rather than timeout::kernel_1a.

--HG--
rename : dlib/timeout/timeout_kernel_1.h => dlib/timeout/timeout.h
rename : dlib/timeout/timeout_kernel_abstract.h => dlib/timeout/timeout_abstract.h
This commit is contained in:
Davis King 2012-11-17 17:47:35 -05:00
parent 83ff1e3e1e
commit 29121937c3
3 changed files with 19 additions and 35 deletions

View File

@ -3,26 +3,7 @@
#ifndef DLIB_TIMEOUt_
#define DLIB_TIMEOUt_
#include "timeout/timeout_kernel_1.h"
namespace dlib
{
class timeout
{
timeout() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef timeout_kernel_1
kernel_1a;
};
}
#include "timeout/timeout.h"
#endif // DLIB_TIMEOUt_

View File

@ -6,7 +6,7 @@
#include "../threads.h"
#include "../algs.h"
#include "../misc_api.h"
#include "timeout_kernel_abstract.h"
#include "timeout_abstract.h"
#include "../uintn.h"
#include "../timer.h"
@ -23,7 +23,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class timeout_kernel_1
class timeout
{
/*!
INITIAL VALUE
@ -62,15 +62,18 @@ namespace dlib
public:
// This typedef is here for backwards compatibility with previous versions of dlib.
typedef timeout kernel_1a;
template <
typename T
>
timeout_kernel_1 (
timeout (
T& object,
void (T::*callback_function)(),
unsigned long ms_to_timeout
):
t(*this,&timeout_kernel_1::trigger_timeout)
t(*this,&timeout::trigger_timeout)
{
zero<T,void>* B = new zero<T,void>;
b = B;
@ -84,13 +87,13 @@ namespace dlib
typename T,
typename U
>
timeout_kernel_1 (
timeout (
T& object,
void (T::*callback_function)(U callback_function_argument),
unsigned long ms_to_timeout,
U callback_function_argument
):
t(*this,&timeout_kernel_1::trigger_timeout)
t(*this,&timeout::trigger_timeout)
{
one<T,void,U>* B = new one<T,void,U>;
b = B;
@ -104,12 +107,12 @@ namespace dlib
template <
typename T
>
timeout_kernel_1 (
timeout (
T& object,
int (T::*callback_function)(),
unsigned long ms_to_timeout
):
t(*this,&timeout_kernel_1::trigger_timeout)
t(*this,&timeout::trigger_timeout)
{
zero<T,int>* B = new zero<T,int>;
b = B;
@ -123,13 +126,13 @@ namespace dlib
typename T,
typename U
>
timeout_kernel_1 (
timeout (
T& object,
int (T::*callback_function)(U callback_function_argument),
unsigned long ms_to_timeout,
U callback_function_argument
):
t(*this,&timeout_kernel_1::trigger_timeout)
t(*this,&timeout::trigger_timeout)
{
one<T,int,U>* B = new one<T,int,U>;
b = B;
@ -140,7 +143,7 @@ namespace dlib
t.start();
}
virtual ~timeout_kernel_1 (
virtual ~timeout (
)
{
t.stop_and_wait();
@ -155,12 +158,12 @@ namespace dlib
t.stop();
}
dlib::timer<timeout_kernel_1>::kernel_2a t;
dlib::timer<timeout>::kernel_2a t;
bind* b;
// restricted functions
timeout_kernel_1(const timeout_kernel_1&); // copy constructor
timeout_kernel_1& operator=(const timeout_kernel_1&); // assignment operator
timeout(const timeout&); // copy constructor
timeout& operator=(const timeout&); // assignment operator
};

View File

@ -20,7 +20,7 @@ namespace dlib
connection* con = a connection from somewhere;
{
// setup a timer that will call con->shutdown() in 10 seconds
timeout::kernel_1a t(*con,&connection::shutdown,10000);
timeout t(*con,&connection::shutdown,10000);
// Now call read on the connection. If this call to read() takes
// more than 10 seconds then the t timeout will trigger and shutdown
// the connection. If read completes in less than 10 seconds then