// Copyright (C) 2003  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#ifndef DLIB_SERVER_KERNEl_C_
#define DLIB_SERVER_KERNEl_C_

#include "server_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
#include "../sockets.h"
#include <string>
#include <sstream>

namespace dlib
{


    template <
        typename server_base
        >
    class server_kernel_c : public server_base
    {
        
        public:

            void start (
            );


            void set_listening_port (
                int port
            );

            void set_listening_ip (
                const std::string& ip
            );

            void set_max_connections (
                int max
            );

    private:

    };

// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
    // member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------

    template <
        typename server_base
        >
    void server_kernel_c<server_base>::
    start (
    )
    {
        // make sure requires clause is not broken
        DLIB_CASSERT( 
              this->is_running() == false,
            "\tvoid server::start"
            << "\n\tis_running() == " << this->is_running() 
            << "\n\tthis: " << this
            );

        // call the real function
        server_base::start();
    }

// ----------------------------------------------------------------------------------------

    template <
        typename server_base
        >
    void server_kernel_c<server_base>::
    set_max_connections (
        int max
    )
    {
        // make sure requires clause is not broken
        DLIB_CASSERT( 
            max >= 0 ,
            "\tvoid server::set_max_connections"
            << "\n\tmax == " << max
            << "\n\tthis: " << this
            );

        // call the real function
        server_base::set_max_connections(max);
    }

// ----------------------------------------------------------------------------------------

    template <
        typename server_base
        >
    void server_kernel_c<server_base>::
    set_listening_port (
        int port
    )
    {
        // make sure requires clause is not broken
        DLIB_CASSERT( 
            ( port >= 0 &&
              this->is_running() == false ),
            "\tvoid server::set_listening_port"
            << "\n\tport         == " << port
            << "\n\tis_running() == " << this->is_running() 
            << "\n\tthis: " << this
            );

        // call the real function
        server_base::set_listening_port(port);
    }

// ----------------------------------------------------------------------------------------

    template <
        typename server_base
        >
    void server_kernel_c<server_base>::
    set_listening_ip (
        const std::string& ip
    ) 
    {
        // make sure requires clause is not broken
        DLIB_CASSERT( 
            ( ( is_ip_address(ip) || ip == "" ) &&
              this->is_running() == false ),
            "\tvoid server::set_listening_ip"
            << "\n\tip           == " << ip
            << "\n\tis_running() == " << this->is_running() 
            << "\n\tthis: " << this
            );

        // call the real function
        server_base::set_listening_ip(ip);
    }

// ----------------------------------------------------------------------------------------

}

#endif // DLIB_SERVER_KERNEl_C_

