Exemplo n.º 1
0
    void Application::termInternal()
    {
        ECSManager* ecsManager = &System::getECSManager();
        ECSManager::destroy(ecsManager);

        Renderer* renderer = &System::getRenderer();
        renderer->terminate();
        LDELETE(renderer);

        CollideManager* collideManager = &System::getCollideManager();
        LDELETE(collideManager);

        Resources* resources = &System::getResources();
        Resources::destroy(resources);

        lsound::Context::terminate();

        lcore::FileSystem* fileSystem = &System::getFileSystem();
        LDELETE(fileSystem);

        input_.terminate();

        lgfx::terminateGraphics();
        window_.destroy();

        System::clear();
    }
Exemplo n.º 2
0
void
kmmint_delist_plugin(kmm_plugin_i * p)
{
    EnterCriticalSection(&cs_kmm);
    if(p->flags & KMM_PLUGIN_FLAG_IN_LIST) {
        p->flags &= ~KMM_PLUGIN_FLAG_IN_LIST;
        LDELETE(&kmm_listed_plugins, p);
    }
    if(p->flags & KMM_PLUGIN_FLAG_IN_MODLIST) {
        p->flags &= ~KMM_PLUGIN_FLAG_IN_MODLIST;
        LDELETE(&(p->module->plugins), p);
    }
    LeaveCriticalSection(&cs_kmm);
}
Exemplo n.º 3
0
/* called with cs_kmm held */
void kmmint_free_module(kmm_module_i * m)
{
    m->magic = 0;

    hash_del(hash_modules, m->name);
    LDELETE(&kmm_all_modules, m);

    if (m->name)
        PFREE(m->name);

    if (m->description)
        PFREE(m->description);

    if (m->path)
        PFREE(m->path);

    if (m->vendor)
        PFREE(m->vendor);

    if (m->support)
        PFREE(m->support);

    if (m->version_info)
        PFREE(m->version_info);

    PFREE(m);
}
Exemplo n.º 4
0
/*! \internal
    \brief Frees a message object
    \note called with ::cs_kmq_msg held
    */
void
kmqint_put_message(kmq_message *m) {
    int queued;
    /* we can only free a message if the refcount is zero.
       Otherwise we have to wait until the call is freed. */
    if(m->refcount == 0) {
        LDELETE(&msg_active, m);
        LeaveCriticalSection(&cs_kmq_msg);
        queued = kmqint_notify_msg_completion(m);
        EnterCriticalSection(&cs_kmq_msg);
        if (!queued) {
            if(m->err_ctx) {
                kherr_release_context(m->err_ctx);
                m->err_ctx = NULL;
            }
            if(m->wait_o) {
                CloseHandle(m->wait_o);
                m->wait_o = NULL;
            }
            LPUSH(&msg_free,m);
        }
    } else if(m->wait_o) {
        SetEvent(m->wait_o);
    }
}
Exemplo n.º 5
0
KHMEXP khm_int32 KHMAPI 
kcdb_credset_delete(khm_handle vcredset)
{
    kcdb_credset * cs;
    int i;

    if(!kcdb_credset_is_credset(vcredset)) {
        return KHM_ERROR_INVALID_PARAM;
    }

    cs = (kcdb_credset *) vcredset;

    EnterCriticalSection(&cs_credset);
    LDELETE(&kcdb_credsets, cs);
    LeaveCriticalSection(&cs_credset);

    EnterCriticalSection(&(cs->cs));
    cs->magic = 0;

    for(i=0;i<cs->nclist;i++) {
        if(cs->clist[i].cred) {
            kcdb_cred_release((khm_handle) cs->clist[i].cred);
        }
    }
    kcdb_credset_buf_delete(cs);

    LeaveCriticalSection(&(cs->cs));
    DeleteCriticalSection(&(cs->cs));

    PFREE(cs);

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 6
0
/* called with cs_mkq_global && cs_kmq_types held */
void kmqint_free_msg_type(int t) {
    kmq_msg_type * pt;
    kmq_msg_subscription * s;

    pt = msg_types[t];

    msg_types[t] = NULL;

    if (pt == NULL)
        return;

    /* all the subscriptions attached to a message type are owned by
       the message type */
    LPOP(&pt->subs, &s);
    while(s) {
        s->magic = 0;

        PFREE(s);

        LPOP(&pt->subs, &s);
    }

    pt->completion_handler = NULL;

    LDELETE(&all_msg_types, pt);

    PFREE(pt);
}
Exemplo n.º 7
0
KHMEXP void *
perf_realloc(const char * file, int line, void * data, size_t s) {
    void * n_data;
    allocation * a;
    size_t h;

    if (data == NULL)
        return perf_malloc(file, line, s);

    perf_once();
    h = HASHPTR(data);

    n_data = realloc(data, s);

    assert(n_data);

    EnterCriticalSection(&cs_alloc);
    for (a = ht[h]; a; a = LNEXT(a)) {
        if (a->ptr == data)
            break;
    }

    assert(a);

    LDELETE(&ht[h], a);

    a->size = s;
    a->ptr = n_data;

    h = HASHPTR(n_data);
    LPUSH(&ht[h], a);
    LeaveCriticalSection(&cs_alloc);

    return n_data;
}
Exemplo n.º 8
0
/*! \internal
    \brief Delete a callback from a message type
    \note Obtains ::cs_kmq_types, ::cs_kmq_global
    */
kmq_msg_subscription * kmqint_msg_type_del_sub_cb(khm_int32 t, kmq_callback_t cb) {
    kmq_msg_subscription *s;
    kmq_queue *q;

    if(t < 0 || t > KMQ_MSG_TYPE_MAX)
        return NULL;

    if(!msg_types[t])
        return NULL;

    q = kmqint_get_thread_queue();

    EnterCriticalSection(&cs_kmq_types);
    s = msg_types[t]->subs;
    while(s) {
        kmq_msg_subscription * n = LNEXT(s);
        if(s->rcpt_type == KMQ_RCPTTYPE_CB &&
           s->recipient.cb == cb &&
           s->queue == q) {
            /*TODO: do more here? */
            LDELETE(&msg_types[t]->subs, s);
            break;
        }
        s = n;
    }
    LeaveCriticalSection(&cs_kmq_types);

    return s;
}
Exemplo n.º 9
0
/* Called with cs_credtype held */
void kcdb_credtype_check_and_delete(khm_int32 id)
{
    kcdb_credtype_i * ict;

#ifdef DEBUG
    assert(id >= 1 && id <= KCDB_CREDTYPE_MAX_ID);
#endif
    if (id < 1 || id > KCDB_CREDTYPE_MAX_ID)
        return;

    ict = kcdb_credtype_tbl[id];
    if(!ict)
        return;

    if((ict->flags & KCDB_CTI_FLAG_DELETED) &&
        !ict->refcount)
    {
        kcdb_credtype_tbl[id] = NULL;
        LDELETE(&kcdb_credtypes, ict);

        PFREE(ict->ct.name);
        if(ict->ct.short_desc)
            PFREE(ict->ct.short_desc);
        if(ict->ct.long_desc)
            PFREE(ict->ct.long_desc);
        if(ict->ct.sub)
            kmq_delete_subscription(ict->ct.sub);

        PFREE(ict);
    }
}
Exemplo n.º 10
0
/* Should NOT be called with cs_error held */
KHMEXP void KHMAPI
kherr_push_new_context(khm_int32 flags)
{
    kherr_context * p = NULL;
    kherr_context * c;

    flags &= KHERR_CFMASK_INITIAL;

    EnterCriticalSection(&cs_error);
    p = peek_context();
    c = get_empty_context();
    if(IS_KHERR_CTX(p)) {
        LDELETE(&ctx_root_list, c);
#ifdef DEBUG
        assert(TPARENT(c) == NULL);
#endif
        TADDCHILD(p,c);
        c->flags &= ~KHERR_CF_UNBOUND;
        kherr_hold_context(p);
    }
    c->flags |= flags;
    push_context(c);

    notify_ctx_event(KHERR_CTX_BEGIN, c, NULL, NULL, 0);
    if (IS_KHERR_CTX(p)) {
        notify_ctx_event(KHERR_CTX_NEWCHILD, p, c, NULL, 0);
    }

    LeaveCriticalSection(&cs_error);
}
Exemplo n.º 11
0
 bool Application::initApplication(InitParam& initParam, const char* title, WNDPROC wndProc)
 {
     Application* instance = LNEW Application;
     if(!instance->initInternal(initParam, title, wndProc)){
         LDELETE(instance);
         return false;
     }
     return true;
 }
Exemplo n.º 12
0
/*! \internal
    \brief Delete a subscription
    \note Obtains ::cs_kmq_types
    */
void kmqint_msg_type_del_sub(kmq_msg_subscription *s) {
    int t = s->type;

    EnterCriticalSection(&cs_kmq_types);
    if(msg_types[t]) {
        LDELETE(&msg_types[t]->subs,s);
    }
    LeaveCriticalSection(&cs_kmq_types);
}
Exemplo n.º 13
0
/* MUST be called with cs_error held */
static void
release_context(kherr_context * c)
{
    if (IS_KHERR_CTX(c)) {
        c->refcount--;

        {
            kherr_event * e;

            e = QBOTTOM(c);
            if (IS_KHERR_EVENT(e) && !(e->flags & KHERR_RF_COMMIT)) {
                commit_event(c, e);
            }
        }

        if (c->refcount == 0) {
            kherr_context * p;

            if (CTX_USES_OWN_PROGRESS(c)) {
                set_and_notify_progress_change(c, 256, 256);
            }

            p = TPARENT(c);

#ifdef DEBUG
	    kherr_debug_printf(L"Posting KHERR_CTX_END for %p\n", (void *) c);
#endif
            notify_ctx_event(KHERR_CTX_END, c, NULL, NULL, 0);

            if (IS_KHERR_CTX(p)) {
                kherr_event * e;

                e = fold_context(c);
                TDELCHILD(p, c);
                
		if (e) {
                    add_event(p, e);
		    notify_ctx_event(KHERR_CTX_FOLDCHILD, p, NULL, e, 0);
		}

                release_context(p);
            } else {
                LDELETE(&ctx_root_list, c);
            }
            free_context(c);
        }
    }
}
Exemplo n.º 14
0
KHMEXP khm_int32 KHMAPI kmq_delete_subscription(khm_handle sub)
{
    kmq_msg_subscription * s;

    s = (kmq_msg_subscription *) sub;

    assert(s->magic == KMQ_MSG_SUB_MAGIC);

    s->type = 0;

    EnterCriticalSection(&cs_kmq_global);
    LDELETE(&kmq_adhoc_subs, s);
    LeaveCriticalSection(&cs_kmq_global);

    PFREE(s);

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 15
0
/* called with cs_identpro held */
static void
identpro_check_and_deleteL(kcdb_identpro_i * p)
{
    if (!(p->flags & KCDB_IDENTPRO_FLAG_DELETED) ||
        p->refcount > 0)
        return;

    p->magic = 0;
    if (p->name)
        PFREE(p->name);
    if (p->sub)
        kmq_delete_subscription(p->sub);
    if (p->plugin)
        kmm_release_plugin(p->plugin);
    LDELETE(&deleted_id_providers, p);
    ZeroMemory(p, sizeof(*p));
    PFREE(p);
}
Exemplo n.º 16
0
void kcdb_type_check_and_delete(khm_int32 id)
{
    kcdb_type_i * t;

    if(id < 0 || id > KCDB_TYPE_MAX_ID)
        return;

    EnterCriticalSection(&cs_type);
    t = kcdb_type_tbl[id];
    if(t && !t->refcount) {
        kcdb_type_tbl[id] = NULL;
        LDELETE(&kcdb_types, t);
        /* must already be out of the hash-table, otherwise refcount should not
            be zero */
        PFREE(t->type.name);
        PFREE(t);
    }
    LeaveCriticalSection(&cs_type);
}
Exemplo n.º 17
0
KHMEXP void
perf_free  (void * b) {
    size_t h;
    allocation * a;

    perf_once();
    h = HASHPTR(b);

    EnterCriticalSection(&cs_alloc);
    for(a = ht[h]; a; a = LNEXT(a)) {
        if (a->ptr == b)
            break;
    }

    assert(a);

    LDELETE(&ht[h], a);
    LPUSH(&free_alloc, a);
    LeaveCriticalSection(&cs_alloc);
}
Exemplo n.º 18
0
/* called with cs_alert held */
static void 
free_alert(khui_alert * alert)
{
    assert(alert->magic == KHUI_ALERT_MAGIC);

    LDELETE(&kh_alerts, alert);

    if(alert->flags & KHUI_ALERT_FLAG_FREE_TITLE) {
        assert(alert->title);
        PFREE(alert->title);
        alert->title = NULL;
        alert->flags &= ~KHUI_ALERT_FLAG_FREE_TITLE;
    }

    if(alert->flags & KHUI_ALERT_FLAG_FREE_MESSAGE) {
        assert(alert->message);
        PFREE(alert->message);
        alert->message = NULL;
        alert->flags &= ~KHUI_ALERT_FLAG_FREE_MESSAGE;
    }

    if(alert->flags & KHUI_ALERT_FLAG_FREE_SUGGEST) {
        assert(alert->suggestion);
        PFREE(alert->suggestion);
        alert->suggestion = NULL;
        alert->flags &= ~KHUI_ALERT_FLAG_FREE_SUGGEST;
    }

    khui_context_release(&alert->ctx);

    if (alert->err_context) {
        kherr_release_context(alert->err_context);
        alert->err_context = NULL;
    }

    if(alert->flags & KHUI_ALERT_FLAG_FREE_STRUCT) {
        alert->flags &= ~KHUI_ALERT_FLAG_FREE_STRUCT;
        alert->magic = 0;
        PFREE(alert);
    }
}
Exemplo n.º 19
0
/*! \internal
    \brief Deletes a window subscription from a message type
    \note Obtains ::cs_kmq_types
*/
kmq_msg_subscription * kmqint_msg_type_del_sub_hwnd(khm_int32 t, HWND hwnd) {
    kmq_msg_subscription *s = NULL;

    if(t < 0 || t > KMQ_MSG_TYPE_MAX)
        return NULL;

    EnterCriticalSection(&cs_kmq_types);
    if(msg_types[t]) {
        s = msg_types[t]->subs;
        while(s) {
            kmq_msg_subscription * n = LNEXT(s);
            if(s->rcpt_type == KMQ_RCPTTYPE_HWND && s->recipient.hwnd == hwnd) {
                /*TODO: do more here? */
                LDELETE(&msg_types[t]->subs, s);
                break;
            }
            s = n;
        }
    }
    LeaveCriticalSection(&cs_kmq_types);

    return s;
}
Exemplo n.º 20
0
 void Application::termApplication()
 {
     Application* application = &System::getApplication();
     application->termInternal();
     LDELETE(application);
 }
Exemplo n.º 21
0
static kcdb_identpro_i *
identpro_create_with_plugin(kmm_plugin plugin, khm_handle sub)
{
    kmm_plugin_info pi;
    kcdb_identpro_i * p;
    size_t len;

    ZeroMemory(&pi, sizeof(pi));
    if (KHM_FAILED(kmm_get_plugin_info_i(plugin, &pi)))
        return NULL;

    if (pi.reg.type != KHM_PITYPE_IDENT) {
        kmm_release_plugin_info_i(&pi);
#ifdef DEBUG
        assert(FALSE);
#endif
        return NULL;
    }

    if (FAILED(StringCbLength(pi.reg.name, KMM_MAXCB_NAME, &len)))
        return NULL;
    len += sizeof(wchar_t);

    /* we need to check if the plug-in is already there, both in the
       current and the deleted lists */
    EnterCriticalSection(&cs_identpro);
    for (p = QTOP(&id_providers); p; p = QNEXT(p)) {
        if (p->plugin == plugin)
            break;
    }

    if (p == NULL)
        for (p = deleted_id_providers; p; p = LNEXT(p)) {
            if (p->plugin == plugin ||
                !wcscmp(p->name, pi.reg.name))
                break;
        }

    if (p)
        identpro_hold(p);

    if (p == NULL) {
        p = PMALLOC(sizeof(*p));
        ZeroMemory(p, sizeof(*p));

        p->magic = KCDB_IDENTPRO_MAGIC;
        p->name = PMALLOC(len);
        StringCbCopy(p->name, len, pi.reg.name);
        p->sub = sub;
        p->plugin = plugin;
        kmm_hold_plugin(plugin);

        p->refcount = 1;            /* initially held */

        QPUT(&id_providers, p);

        n_id_providers++;
        kcdbint_identpro_post_message(KCDB_OP_INSERT, p);

    } else if (p->flags & KCDB_IDENTPRO_FLAG_DELETED) {

        LDELETE(&deleted_id_providers, p);
        p->flags &= ~KCDB_IDENTPRO_FLAG_DELETED;
        if (p->plugin != plugin) {
            /* can happen if the plug-in was reloaded */
            if (p->plugin)
                kmm_release_plugin_info_i(p->plugin);
            p->plugin = plugin;
            kmm_hold_plugin(plugin);
        }

        if (p->sub) {
            kmq_delete_subscription(p->sub);
        }

        p->sub = sub;

        QPUT(&id_providers, p);
        n_id_providers++;
    }

    identpro_check_and_set_default_provider();
    LeaveCriticalSection(&cs_identpro);

    kmm_release_plugin_info_i(&pi);

    return p;
}