/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

/**
 * @file dworker.h
 * @brief provides public interface for dworker modules.
 */

#ifndef _DWORKER_H_
#define _DWORKER_H_

#include "dw_version.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef struct dw_ctxt_t dw_ctxt_t;
typedef struct dw_req_t dw_req_t;

typedef struct dw_module_struct dw_module_t;

typedef void (*dw_module_register_cb)(dw_ctxt_t *dwc, dw_module_t *dmod);

struct dw_module_struct {
    /** Used to check the module's version number is compatible 
     *  with dworker's current version.
     */
    int version;
    
    /** @private : Internal DSO handle for this module. */
    void *dso_handle;
        
    /** __FILE__ from the module */
    const char *name;

    dw_module_register_cb register_func;
};

/**
 * We only have a single level Module Magic Number, 
 * Unlike httpd, which is a two level, with compat stuff. meh. */
#define DW_MODULE_VERSION 0x00000001

#define DW_STANDARD_MODULE_STUFF \
            DW_MODULE_VERSION,   \
            NULL,                \
            __FILE__

#define DW_MODULE_DECL(modname, regfunc) \
    dw_module_t dw_ ## modname ## _module =     \
    {                                    \
        DW_STANDARD_MODULE_STUFF,        \
        regfunc                          \
    };

typedef int(*dw_handler_cb)(dw_req_t* dwr, char *param,
                            apr_size_t len, void* baton);

apr_status_t dw_req_send_result(dw_req_t *dwr,
                                const char *data, apr_size_t len);

void dw_register_handler(dw_ctxt_t *dwc, dw_module_t *mod, const char *cmd,
                         dw_handler_cb func_cp, void *baton);

dw_ctxt_t *dw_req_get_context(dw_req_t *pwr);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _DWORKER_H_ */
