/* Copyright 2000-2006 The Apache Software Foundation or its licensors, as
 * applicable.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CACHE_REQUESTER_THREADPOOL_H
#define CACHE_REQUESTER_THREADPOOL_H
#endif

#include "apr_thread_proc.h"
#include "mod_cache.h"
#include "cache_pqueue.h"
#include "cache_cache.h"
#include "ap_provider.h"
#include "apr_pools.h"
#include "ap_mpm.h"
#include "apr_thread_mutex.h"
#include "apr_thread_cond.h"
#include "apr_strings.h"
#include <curl/curl.h>




// Structure to store the parameters. Currently we support 'number of threads' and 'queue_size of soon-to-expire pages' parameters.
typedef struct cache_req_conf {
    long number_of_threads;
    long queue_size;
    long expiring_signal_time_in_seconds;
    char *secret_code;
} cache_req_conf_t;


// Linked list structure of  threads. each instance contains pointer to the thread and pointer to next instance of the linked list.
typedef struct cache_req_thread {
    apr_thread_t *handle;
    struct cache_req_thread *next;
}cache_req_thread;

// request object to be stored in the queue for each soon-to-expire page.
typedef struct cache_req_expiring_page {
    char *uri;
    char *request_uri;
    long priority;
    apr_uint32_t pos;
    struct cache_req_expiring_page *next;
}cache_req_expiring_page;

// thread pool. 
// contains thread queue, lock, condition variable.
typedef struct cache_req_thread_pool {
    cache_req_thread *queue;

    //cache_requester_request *processing_requests;
}cache_req_thread_pool;

// main structure, which uses all the above structures and keeps them organized.
typedef struct cache_requester {
    cache_req_thread_pool *thread_pool;

    cache_pqueue_t *cache_request_pq;
    apr_hash_t *expiring_page_hash;
    apr_thread_mutex_t *lock;
    apr_thread_cond_t *cond;

    apr_pool_t *pool;
}cache_requester;
