/*
 * ex: set ro:
 * DO NOT EDIT.
 * generated by smc (http://smc.sourceforge.net/)
 * from file : txc_client.sm
 */


/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
*	
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*	
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*	
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/

/**
 * @brief XDMC State Machine Implementation
 *
 * @author Mamadou Diop <diopmamadou(at)yahoo.fr>
 *
 * @date Created: Sat Nov 8 16:54:58 2009 mdiop
 */
 

#include <assert.h>
#include "txc_client.h"
#include "..\..\tinyXCAP\src\txc_client_sm.h"

#define getOwner(fsm) \
    (fsm)->_owner

#define POPULATE_STATE(state) \
    state##_Entry, \
    state##_Connect, \
    state##_Failure, \
    state##_Success, \
    state##_Default

#define ENTRY_STATE(state) \
    if ((state)->Entry != NULL) { \
        (state)->Entry(fsm); \
    }

#define EXIT_STATE(state)

static void txc_xdmcState_Connect(struct txc_xdmcContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void txc_xdmcState_Failure(struct txc_xdmcContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void txc_xdmcState_Success(struct txc_xdmcContext *fsm)
{
    getState(fsm)->Default(fsm);
}

static void txc_xdmcState_Default(struct txc_xdmcContext *fsm)
{
    State_Default(fsm);
}

#define txc_xdmc_Started_Connect txc_xdmcState_Connect
#define txc_xdmc_Started_Failure txc_xdmcState_Failure
#define txc_xdmc_Started_Success txc_xdmcState_Success
#define txc_xdmc_Started_Default txc_xdmcState_Default
#define txc_xdmc_Started_Entry NULL
#define txc_xdmc_Started_Exit NULL
#define txc_xdmc_DISCONNECTED_Connect txc_xdmcState_Connect
#define txc_xdmc_DISCONNECTED_Failure txc_xdmcState_Failure
#define txc_xdmc_DISCONNECTED_Success txc_xdmcState_Success
#define txc_xdmc_DISCONNECTED_Default txc_xdmcState_Default
#define txc_xdmc_DISCONNECTED_Entry NULL
#define txc_xdmc_DISCONNECTED_Exit NULL
#define txc_xdmc_CONNECTED_Connect txc_xdmcState_Connect
#define txc_xdmc_CONNECTED_Failure txc_xdmcState_Failure
#define txc_xdmc_CONNECTED_Success txc_xdmcState_Success
#define txc_xdmc_CONNECTED_Default txc_xdmcState_Default
#define txc_xdmc_CONNECTED_Entry NULL
#define txc_xdmc_CONNECTED_Exit NULL
#define txc_xdmc_GET_XCAP_CAPS_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_XCAP_CAPS_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_XCAP_CAPS_Success txc_xdmcState_Success
#define txc_xdmc_GET_XCAP_CAPS_Default txc_xdmcState_Default
#define txc_xdmc_GET_XCAP_CAPS_Entry NULL
#define txc_xdmc_GET_XCAP_CAPS_Exit NULL
#define txc_xdmc_GET_OMADIR_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_OMADIR_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_OMADIR_Success txc_xdmcState_Success
#define txc_xdmc_GET_OMADIR_Default txc_xdmcState_Default
#define txc_xdmc_GET_OMADIR_Entry NULL
#define txc_xdmc_GET_OMADIR_Exit NULL
#define txc_xdmc_GET_RLIST_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_RLIST_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_RLIST_Success txc_xdmcState_Success
#define txc_xdmc_GET_RLIST_Default txc_xdmcState_Default
#define txc_xdmc_GET_RLIST_Entry NULL
#define txc_xdmc_GET_RLIST_Exit NULL
#define txc_xdmc_GET_RLS_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_RLS_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_RLS_Success txc_xdmcState_Success
#define txc_xdmc_GET_RLS_Default txc_xdmcState_Default
#define txc_xdmc_GET_RLS_Entry NULL
#define txc_xdmc_GET_RLS_Exit NULL
#define txc_xdmc_GET_OMAPRES_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_OMAPRES_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_OMAPRES_Success txc_xdmcState_Success
#define txc_xdmc_GET_OMAPRES_Default txc_xdmcState_Default
#define txc_xdmc_GET_OMAPRES_Entry NULL
#define txc_xdmc_GET_OMAPRES_Exit NULL
#define txc_xdmc_GET_IETFPRES_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_IETFPRES_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_IETFPRES_Success txc_xdmcState_Success
#define txc_xdmc_GET_IETFPRES_Default txc_xdmcState_Default
#define txc_xdmc_GET_IETFPRES_Entry NULL
#define txc_xdmc_GET_IETFPRES_Exit NULL
#define txc_xdmc_GET_OMAPRESCONT_Connect txc_xdmcState_Connect
#define txc_xdmc_GET_OMAPRESCONT_Failure txc_xdmcState_Failure
#define txc_xdmc_GET_OMAPRESCONT_Success txc_xdmcState_Success
#define txc_xdmc_GET_OMAPRESCONT_Default txc_xdmcState_Default
#define txc_xdmc_GET_OMAPRESCONT_Entry NULL
#define txc_xdmc_GET_OMAPRESCONT_Exit NULL
#define txc_xdmc_DefaultState_Connect txc_xdmcState_Connect
#define txc_xdmc_DefaultState_Failure txc_xdmcState_Failure
#define txc_xdmc_DefaultState_Success txc_xdmcState_Success

#undef txc_xdmc_Started_Entry
void txc_xdmc_Started_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_state_set(ctxt, txs_initialized);
}

#undef txc_xdmc_Started_Connect
static void txc_xdmc_Started_Connect(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_GET_XCAP_CAPS);
    ENTRY_STATE(getState(fsm));
}

const struct txc_xdmcState txc_xdmc_Started = { POPULATE_STATE(txc_xdmc_Started), "txc_xdmc_Started", 0 };

#undef txc_xdmc_DISCONNECTED_Entry
void txc_xdmc_DISCONNECTED_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_connection_set(ctxt, 0);
}

const struct txc_xdmcState txc_xdmc_DISCONNECTED = { POPULATE_STATE(txc_xdmc_DISCONNECTED), "txc_xdmc_DISCONNECTED", 1 };

#undef txc_xdmc_CONNECTED_Entry
void txc_xdmc_CONNECTED_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_connection_set(ctxt, 1);
}

const struct txc_xdmcState txc_xdmc_CONNECTED = { POPULATE_STATE(txc_xdmc_CONNECTED), "txc_xdmc_CONNECTED", 2 };

#undef txc_xdmc_GET_XCAP_CAPS_Entry
void txc_xdmc_GET_XCAP_CAPS_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_caps(ctxt);
}

#undef txc_xdmc_GET_XCAP_CAPS_Failure
static void txc_xdmc_GET_XCAP_CAPS_Failure(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_DISCONNECTED);
    ENTRY_STATE(getState(fsm));
}

#undef txc_xdmc_GET_XCAP_CAPS_Success
static void txc_xdmc_GET_XCAP_CAPS_Success(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_OMADIR);
        ENTRY_STATE(getState(fsm));
    }
    else if (!TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_CONNECTED);
        ENTRY_STATE(getState(fsm));
    }    else {
        txc_xdmc_DefaultState_Success(fsm);
    }
}

const struct txc_xdmcState txc_xdmc_GET_XCAP_CAPS = { POPULATE_STATE(txc_xdmc_GET_XCAP_CAPS), "txc_xdmc_GET_XCAP_CAPS", 3 };

#undef txc_xdmc_GET_OMADIR_Entry
void txc_xdmc_GET_OMADIR_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_omadir(ctxt);
}

#undef txc_xdmc_GET_OMADIR_Default
static void txc_xdmc_GET_OMADIR_Default(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_CONNECTED);
    ENTRY_STATE(getState(fsm));
}

#undef txc_xdmc_GET_OMADIR_Failure
static void txc_xdmc_GET_OMADIR_Failure(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_RLIST);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Failure(fsm);
    }
}

#undef txc_xdmc_GET_OMADIR_Success
static void txc_xdmc_GET_OMADIR_Success(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_RLIST);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Success(fsm);
    }
}

const struct txc_xdmcState txc_xdmc_GET_OMADIR = { POPULATE_STATE(txc_xdmc_GET_OMADIR), "txc_xdmc_GET_OMADIR", 4 };

#undef txc_xdmc_GET_RLIST_Entry
void txc_xdmc_GET_RLIST_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_rlist(ctxt);
}

#undef txc_xdmc_GET_RLIST_Default
static void txc_xdmc_GET_RLIST_Default(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_CONNECTED);
    ENTRY_STATE(getState(fsm));
}

#undef txc_xdmc_GET_RLIST_Failure
static void txc_xdmc_GET_RLIST_Failure(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_RLS);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Failure(fsm);
    }
}

#undef txc_xdmc_GET_RLIST_Success
static void txc_xdmc_GET_RLIST_Success(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_RLS);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Success(fsm);
    }
}

const struct txc_xdmcState txc_xdmc_GET_RLIST = { POPULATE_STATE(txc_xdmc_GET_RLIST), "txc_xdmc_GET_RLIST", 5 };

#undef txc_xdmc_GET_RLS_Entry
void txc_xdmc_GET_RLS_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_rls(ctxt);
}

#undef txc_xdmc_GET_RLS_Default
static void txc_xdmc_GET_RLS_Default(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_CONNECTED);
    ENTRY_STATE(getState(fsm));
}

#undef txc_xdmc_GET_RLS_Failure
static void txc_xdmc_GET_RLS_Failure(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_OMAPRES);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Failure(fsm);
    }
}

#undef txc_xdmc_GET_RLS_Success
static void txc_xdmc_GET_RLS_Success(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_OMAPRES);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Success(fsm);
    }
}

const struct txc_xdmcState txc_xdmc_GET_RLS = { POPULATE_STATE(txc_xdmc_GET_RLS), "txc_xdmc_GET_RLS", 6 };

#undef txc_xdmc_GET_OMAPRES_Entry
void txc_xdmc_GET_OMAPRES_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_omapres(ctxt);
}

#undef txc_xdmc_GET_OMAPRES_Default
static void txc_xdmc_GET_OMAPRES_Default(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_CONNECTED);
    ENTRY_STATE(getState(fsm));
}

#undef txc_xdmc_GET_OMAPRES_Failure
static void txc_xdmc_GET_OMAPRES_Failure(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_IETFPRES);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Failure(fsm);
    }
}

#undef txc_xdmc_GET_OMAPRES_Success
static void txc_xdmc_GET_OMAPRES_Success(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_OMAPRESCONT);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Success(fsm);
    }
}

const struct txc_xdmcState txc_xdmc_GET_OMAPRES = { POPULATE_STATE(txc_xdmc_GET_OMAPRES), "txc_xdmc_GET_OMAPRES", 7 };

#undef txc_xdmc_GET_IETFPRES_Entry
void txc_xdmc_GET_IETFPRES_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_ietfpres(ctxt);
}

#undef txc_xdmc_GET_IETFPRES_Default
static void txc_xdmc_GET_IETFPRES_Default(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_CONNECTED);
    ENTRY_STATE(getState(fsm));
}

#undef txc_xdmc_GET_IETFPRES_Failure
static void txc_xdmc_GET_IETFPRES_Failure(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_OMAPRESCONT);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Failure(fsm);
    }
}

#undef txc_xdmc_GET_IETFPRES_Success
static void txc_xdmc_GET_IETFPRES_Success(struct txc_xdmcContext *fsm)
{

    if (TXC_XDMC_FIRSTTIME(getOwner(fsm))) {
        EXIT_STATE(getState(fsm));
        /* No actions. */
        setState(fsm, &txc_xdmc_GET_OMAPRESCONT);
        ENTRY_STATE(getState(fsm));
    }
    else {
        txc_xdmc_DefaultState_Success(fsm);
    }
}

const struct txc_xdmcState txc_xdmc_GET_IETFPRES = { POPULATE_STATE(txc_xdmc_GET_IETFPRES), "txc_xdmc_GET_IETFPRES", 8 };

#undef txc_xdmc_GET_OMAPRESCONT_Entry
void txc_xdmc_GET_OMAPRESCONT_Entry(struct txc_xdmcContext *fsm)
{
    struct txc_xdmc *ctxt = getOwner(fsm);

    txc_xdmc_get_omaprescont(ctxt);
}

#undef txc_xdmc_GET_OMAPRESCONT_Default
static void txc_xdmc_GET_OMAPRESCONT_Default(struct txc_xdmcContext *fsm)
{

    EXIT_STATE(getState(fsm));
    setState(fsm, &txc_xdmc_CONNECTED);
    ENTRY_STATE(getState(fsm));
}

const struct txc_xdmcState txc_xdmc_GET_OMAPRESCONT = { POPULATE_STATE(txc_xdmc_GET_OMAPRESCONT), "txc_xdmc_GET_OMAPRESCONT", 9 };

void txc_xdmcContext_Init(struct txc_xdmcContext* fsm, struct txc_xdmc* owner)
{
    FSM_INIT(fsm, &txc_xdmc_Started);
    fsm->_owner = owner;
}

void txc_xdmcContext_EnterStartState(struct txc_xdmcContext* fsm)
{
    ENTRY_STATE(getState(fsm));
}

void txc_xdmcContext_Connect(struct txc_xdmcContext* fsm)
{
    const struct txc_xdmcState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Connect");
    state->Connect(fsm);
    setTransition(fsm, NULL);
}

void txc_xdmcContext_Failure(struct txc_xdmcContext* fsm)
{
    const struct txc_xdmcState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Failure");
    state->Failure(fsm);
    setTransition(fsm, NULL);
}

void txc_xdmcContext_Success(struct txc_xdmcContext* fsm)
{
    const struct txc_xdmcState* state = getState(fsm);

    assert(state != NULL);
    setTransition(fsm, "Success");
    state->Success(fsm);
    setTransition(fsm, NULL);
}

/*
 * Local variables:
 *  buffer-read-only: t
 * End:
 */
