src/lib/service_internal.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 May 2009 01:17:36 +0300
branchnew-lib-errors
changeset 219 cefec18b8268
parent 175 src/service_internal.h@a816950a6548
permissions -rw-r--r--
some of the lib/transport stuff compiles
#ifndef SERVICE_INTERNAL_H
#define SERVICE_INTERNAL_H

/**
 * @file
 *
 * Internal interface for implementations of service_t
 */
#include "service.h"
#include "transport.h"
#include "object.h"

/**
 * The object_type of service_type
 */
extern const struct object_type service_type_type;

/**
 * Type definition with method table
 */
struct service_type {
    struct object_type base_type;
    
    /** Method table */
    struct service_methods {
        /**
         * Release internal state, but not the service_t itself
         */
        void (*deinit) (service_t *service);
    } methods;
};

/**
 * Base service_t state
 */
struct service {
    struct object base_obj;

    /** User info */
    struct service_info info;
};

/**
 * Initialize a service by binding it to a specific type, with the given user info for this service, and for spawned transports.
 */
void service_init (service_t *service, const struct service_type *type, const struct service_info *info);

/**
 * Used to up-cast a generic service_t pointer to an implementation of the given service_type (or subtype).
 *
 * It is a bug to call this with a service of a different type.
 */
void* service_check (service_t *service, const struct service_type *type);

/**
 * The service failed, call the user callback
 */
void service_error (service_t *service, const error_t *err);

#endif /* SERVICE_INTERNAL_H */