//
// Generated by dtk
// Translation Unit: f_pc_deletor.cpp
//

#include "f_pc/f_pc_deletor.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "SSystem/SComponent/c_list_iter.h"
#include "f_pc/f_pc_creator.h"
#include "f_pc/f_pc_executor.h"
#include "f_pc/f_pc_load.h"
#include "f_pc/f_pc_node.h"

/* 8003D280-8003D2A0       .text fpcDt_IsComplete__Fv */
BOOL fpcDt_IsComplete() {
    return fpcDtTg_IsEmpty();
}

/* 8003D2A0-8003D314       .text fpcDt_deleteMethod__FP18base_process_class */
s32 fpcDt_deleteMethod(base_process_class* i_proc) {
    layer_class* layer = i_proc->mDtTg.mpLayer;
    s16 profName = i_proc->mProfName;

    fpcLy_SetCurrentLayer(layer);
    fpcLnTg_QueueTo(&i_proc->mLnTg);
    if (fpcBs_Delete(i_proc) == 1) {
        fpcLy_DeletedMesg(layer);
        fpcLd_Free(profName);
        return 1;
    } else {
        return 0;
    }
}

/* 8003D314-8003D34C       .text fpcDt_Handler__Fv */
void fpcDt_Handler(void) {
    cLsIt_Method(&g_fpcDtTg_Queue, (cNdIt_MethodFunc)fpcDtTg_Do, (void*)fpcDt_deleteMethod);
}

/* 8003D34C-8003D3C8       .text fpcDt_ToQueue__FP18base_process_class */
BOOL fpcDt_ToQueue(base_process_class* i_proc) {
    if (i_proc->mUnk0 != 1 && fpcBs_IsDelete(i_proc) == TRUE) {
        if (fpcPi_IsInQueue(&i_proc->mPi) == 1) {
            fpcPi_Delete(&i_proc->mPi);
        }
        i_proc->mDtTg.mpLayer = i_proc->mLyTg.mpLayer;
        fpcDtTg_ToDeleteQ(&i_proc->mDtTg);
        fpcLy_DeletingMesg(i_proc->mLyTg.mpLayer);
        return TRUE;
    } else {
        return FALSE;
    }
}

/* 8003D3C8-8003D51C       .text fpcDt_ToDeleteQ__FP18base_process_class */
BOOL fpcDt_ToDeleteQ(base_process_class* i_proc) {
    if (i_proc->mUnk0 == 1) {
        return FALSE;
    } else {
        if (cTg_IsUse(&i_proc->mDtTg.base) != 0) {
            return TRUE;
        } else {
            if (fpcBs_Is_JustOfType(g_fpcNd_type, i_proc->mSubType)) {
                process_node_class* procNode = (process_node_class*)i_proc;
                if (fpcNd_IsDeleteTiming(procNode) == FALSE) {
                    return FALSE;
                } else {
                    layer_class* layer = &procNode->mLayer;

                    if (!fpcLy_Cancel(layer))
                        JUT_ASSERT(196, FALSE);

                    if (fpcLyIt_OnlyHereLY(layer, (fpcLyIt_OnlyHereFunc)fpcDt_ToDeleteQ, NULL) == FALSE) {
                        return FALSE;
                    }
                }
            }

            if (fpcDt_ToQueue(i_proc) == TRUE) {
                if (fpcEx_IsExist(i_proc->mBsPcId) == TRUE) {
                    if (fpcEx_ExecuteQTo(i_proc) == FALSE) {
                        return FALSE;
                    }
                } else {
                    if (fpcCt_Abort(i_proc) == FALSE) {
                        return FALSE;
                    }
                }
                i_proc->mInitState = 3;
                return TRUE;
            } else {
                return FALSE;
            }
        }
    }
}

/* 8003D51C-8003D580       .text fpcDt_Delete__FPv */
BOOL fpcDt_Delete(void* i_proc) {
    base_process_class* proc = static_cast<base_process_class*>(i_proc);
    if (proc != NULL) {
        if (fpcCt_IsDoing(proc) == TRUE)
            return FALSE;

        if (proc->mInitState == 3)
            return FALSE;

        return fpcDt_ToDeleteQ(proc);
    } else {
        return TRUE;
    }
}
