Commit 4edd8795 authored by Davis King's avatar Davis King

Turned linker into a single implementation component.

parent e7baa766
......@@ -4,34 +4,6 @@
#define DLIB_LINKEr_
#include "linker/linker_kernel_1.h"
#include "linker/linker_kernel_c.h"
#include "algs.h"
namespace dlib
{
class linker
{
linker() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef linker_kernel_1
kernel_1a;
typedef linker_kernel_c<kernel_1a>
kernel_1a_c;
};
}
#endif // DLIB_LINKEr_
......@@ -13,8 +13,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
linker_kernel_1::
linker_kernel_1 (
linker::
linker (
) :
running(false),
running_signaler(running_mutex),
......@@ -26,8 +26,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
linker_kernel_1::
~linker_kernel_1 (
linker::
~linker (
)
{
clear();
......@@ -35,7 +35,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void linker_kernel_1::
void linker::
clear (
)
{
......@@ -67,7 +67,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
bool linker_kernel_1::
bool linker::
is_running (
) const
{
......@@ -79,12 +79,20 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void linker_kernel_1::
void linker::
link (
connection& a,
connection& b
)
{
// make sure requires clause is not broken
DLIB_CASSERT(
this->is_running() == false ,
"\tvoid linker::link"
<< "\n\tis_running() == " << this->is_running()
<< "\n\tthis: " << this
);
running_mutex.lock();
running = true;
running_mutex.unlock();
......@@ -127,7 +135,7 @@ namespace dlib
throw dlib::thread_error (
ECREATE_THREAD,
"failed to make new thread in linker_kernel_1::link()"
"failed to make new thread in linker::link()"
);
}
......@@ -219,7 +227,7 @@ namespace dlib
// throw the exception for this error
throw dlib::socket_error (
ECONNECTION,
"a connection returned an error in linker_kernel_1::link()"
"a connection returned an error in linker::link()"
);
}
......@@ -233,12 +241,12 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void linker_kernel_1::
void linker::
service_connection (
void* param
)
{
linker_kernel_1& p = *static_cast<linker_kernel_1*>(param);
linker& p = *static_cast<linker*>(param);
p.cons_mutex.lock();
// if the connections are gone for whatever reason then return
......
......@@ -12,7 +12,7 @@
namespace dlib
{
class linker_kernel_1
class linker
{
/*!
......@@ -21,7 +21,7 @@ namespace dlib
A == 0
B == 0
running_mutex == a mutex
running_signaler == a signaler assocaited with running_mutex
running_signaler == a signaler associated with running_mutex
cons_mutex == a mutex
service_connection_running == false
service_connection_running_mutex == a mutex
......@@ -65,11 +65,16 @@ namespace dlib
public:
// These two typedefs are here for backwards compatibility with previous
// versions of dlib.
typedef linker kernel_1a;
typedef linker kernel_1a_c;
linker_kernel_1(
linker(
);
virtual ~linker_kernel_1(
virtual ~linker(
);
void clear(
......@@ -91,7 +96,7 @@ namespace dlib
);
/*!
requires
param == pointer to a linker_kernel_1 object
param == pointer to a linker object
ensures
waits for data from b and forwards it to a and
if (b closes normally or is shutdown()) service_connection ends and
......@@ -116,8 +121,8 @@ namespace dlib
mutex service_connection_error_mutex;
// restricted functions
linker_kernel_1(linker_kernel_1&); // copy constructor
linker_kernel_1& operator=(linker_kernel_1&); // assignment operator
linker(linker&); // copy constructor
linker& operator=(linker&); // assignment operator
};
......
......@@ -3,7 +3,6 @@
#undef DLIB_LINKER_KERNEl_ABSTRACT_
#ifdef DLIB_LINKER_KERNEl_ABSTRACT_
// non-templateable dependencies
#include "../threads/threads_kernel_abstract.h"
#include "../sockets/sockets_kernel_abstract.h"
......
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_LINKER_KERNEl_C_
#define DLIB_LINKER_KERNEl_C_
#include "linker_kernel_abstract.h"
#include "../sockets.h"
#include "../algs.h"
#include "../assert.h"
namespace dlib
{
template <
typename linker_base
>
class linker_kernel_c : public linker_base
{
public:
void link (
connection& a,
connection& b
);
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename linker_base
>
void linker_kernel_c<linker_base>::
link (
connection& a,
connection& b
)
{
// make sure requires clause is not broken
DLIB_CASSERT(
this->is_running() == false ,
"\tvoid linker::link"
<< "\n\tis_running() == " << this->is_running()
<< "\n\tthis: " << this
);
// call the real function
linker_base::link(a,b);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_LINKER_KERNEl_C_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment