/*----------------------------------------------------------------------------*/
/* forms_cp.cpp                                                               */
/* copyright (c) innovaphone 2013                                             */
/*                                                                            */
/*----------------------------------------------------------------------------*/

#undef  DBG_TRC
#define DBG_TRC(args)   { if (trace) debug->printf args ; }
//#define DBG_TRC(args)   { debug->printf args ; }

#define ARRAY_ITEMS(array) (sizeof(array)/sizeof(array[0]))

static async_forms_cp *forms_cp = NULL;

/*----------------------------------------------------------------------------*/

static int forms_cp_txt_table[] =
{
    TXT_REPAIR_LOST_PHONE_ACCOUNT,
    TXT_SMARTPHONE_RESTART_NEEDED,
    TXT_OVERLAYING_PERMISSION_NEEDED,
};

/*---------------------------------------------------------------------------*/

CPImageSet::CPImageSet(byte *lightContentImage, unsigned lightContentImageLength, byte *darkContentImage, unsigned darkContentImageLength)
{
    this->lightContentImage = lightContentImage;
    this->lightContentImageLength = lightContentImageLength;
    this->darkContentImage = darkContentImage;
    this->darkContentImageLength = darkContentImageLength;
    if (darkContentImage) {
        forms_cp->forms_async->enqueue(FORMS_CP_IMAGE_SET_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), lightContentImage, lightContentImageLength, darkContentImage, darkContentImageLength);
    }
    else {
        forms_cp->forms_async->enqueue(FORMS_CP_UI_IMAGE_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), lightContentImage, lightContentImageLength);
    }
}

CPImageSet::~CPImageSet()
{
    forms_cp->cp_free_id(this);
}

/*---------------------------------------------------------------------------*/

class FormsCPCompletion : public forms_cp_object, public CPCompletion {
    int obj_id;
public:
    FormsCPCompletion(int obj_id);
    ~FormsCPCompletion();
    void complete();
};

FormsCPCompletion::FormsCPCompletion(int obj_id) :
    forms_cp_object(this)
{
    this->obj_id = obj_id;
    forms_cp->set_id_obj(obj_id, this);
}

FormsCPCompletion::~FormsCPCompletion()
{
    forms_cp->forms_async->enqueue(FORMS_ASYNC_DELETE_OBJECT, obj_id);
    forms_cp->set_id_obj(obj_id, NULL);
}

void FormsCPCompletion::complete()
{
    forms_cp->forms_async->enqueue(FORMS_CP_COMPLETION_COMPLETE, obj_id);
    delete this;
}

/*---------------------------------------------------------------------------*/

CPTemplate::CPTemplate()
{
    userInfo = NULL;
}

CPTemplate::~CPTemplate()
{
    forms_cp->cp_free_id(this);
}

/*---------------------------------------------------------------------------*/

CPListItem::CPListItem(const char *text, const char *detailText, CPImageSet *image)
{
    this->text = _strdup(text);
    this->detailText = _strdup(detailText);
    this->image = image;
    if (image) {
        forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_WITH_IMAGE_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), text ? text : "", detailText ? detailText : "", forms_cp->cp_obj_id(image));
    }
    else {
        forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), text ? text : "", detailText ? detailText : "");
    }
}

CPListItem::~CPListItem()
{
    if (text) free(text);
    if (detailText) free(detailText);
    forms_cp->cp_free_id(this);
}

void CPListItem::setText(const char *text)
{
    if (this->text) free(this->text);
    this->text = _strdup(text);
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_SET_TEXT, forms_cp->cp_obj_id(this), text ? text : "");
}

void CPListItem::setDetailText(const char *detailText)
{
    if (this->detailText) free(this->detailText);
    this->detailText = _strdup(detailText);
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_SET_DETAIL_TEXT, forms_cp->cp_obj_id(this), detailText ? detailText : "");
}

void CPListItem::setImage(CPImageSet *image)
{
    this->image = image;
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_SET_IMAGE, forms_cp->cp_obj_id(this), forms_cp->cp_obj_id(image));
}

/*---------------------------------------------------------------------------*/

CPListSection::CPListSection(CPListItem **items, unsigned itemCount)
{
    unsigned i;

    this->items = (CPListItem **)(malloc((itemCount + 1) * sizeof(CPListItem *)));
    memcpy(this->items, items, itemCount * sizeof(CPListItem *));
    this->itemCount = itemCount;
    header = NULL;
    sectionIndexTitle = NULL;
    for (i = 0; i < itemCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_ADD, forms_cp->cp_obj_id(items[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_SECTION_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), header ? header : "", sectionIndexTitle ? sectionIndexTitle : "");
}

CPListSection::CPListSection(CPListItem **items, unsigned itemCount, const char *header, const char *sectionIndexTitle)
{
    unsigned i;

    if (itemCount != 0) {
        this->items = (CPListItem **)(malloc((itemCount + 1) * sizeof(CPListItem *)));
        memcpy(this->items, items, itemCount * sizeof(CPListItem *));
    }
    else {
        this->items = NULL;
    }
    this->itemCount = itemCount;
    this->header = _strdup(header);
    this->sectionIndexTitle = _strdup(sectionIndexTitle);
    for (i = 0; i < itemCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_LIST_ITEM_ADD, forms_cp->obj_id, forms_cp->cp_obj_id(items[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_SECTION_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), header ? header : "", sectionIndexTitle ? sectionIndexTitle : "");
}

CPListSection::~CPListSection()
{
    if (items) free(items);
    if (header) free(header);
    if (sectionIndexTitle) free(sectionIndexTitle);
    forms_cp->cp_free_id(this);
}

unsigned CPListSection::indexOfItem(CPListItem *item)
{
    unsigned i;
    items[itemCount] = item;
    i = 0;
    while (items[i] != item) {
        i++;
    }
    return i;
}

CPListItem *CPListSection::itemAtIndex(unsigned index)
{
    return ((index < itemCount) ? items[index] : NULL);
}

/*---------------------------------------------------------------------------*/

CPListTemplate::CPListTemplate(const char *title, CPListSection **sections, unsigned sectionCount)
{
    unsigned i;

    this->title = _strdup(title);
    if (sectionCount != 0) {
        this->sections = (CPListSection **)(malloc(sectionCount * sizeof(CPListSection *)));
        memcpy(this->sections, sections, sectionCount * sizeof(CPListSection *));
    }
    else {
        this->sections = NULL;
    }
    this->sectionCount = sectionCount;
    delegate = NULL;
    for (i = 0; i < sectionCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_LIST_SECTION_ADD, forms_cp->obj_id, forms_cp->cp_obj_id(sections[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_TEMPLATE_CREATE, forms_cp->obj_id, forms_cp->cp_new_id((CPTemplate *) this), title ? title : "");
}

CPListTemplate::~CPListTemplate()
{
    if (title) free(title);
    if (sections) free(sections);
}

void CPListTemplate::updateSections(CPListSection **sections, unsigned sectionCount)
{
    unsigned i, obj_id;

    free(this->sections);
    this->sections = (CPListSection **)(malloc(sectionCount * sizeof(CPListSection *)));
    memcpy(this->sections, sections, sectionCount * sizeof(CPListSection *));
    this->sectionCount = sectionCount;
    obj_id = forms_cp->cp_obj_id(this);
    for (i = 0; i < sectionCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_LIST_SECTION_ADD, obj_id, forms_cp->cp_obj_id(sections[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_LIST_TEMPLATE_UPDATE_SECTIONS, obj_id);
}

void forms_cp_list_template_did_select_list_item(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    int item_id = async_event->get_int();
    int completion_id = async_event->get_int();
    DBG_TRC(("forms_cp_list_template_did_select_list_item(%i) %i %i", obj_id, item_id, completion_id));
    FormsCPCompletion *completion = new FormsCPCompletion(completion_id);
    CPListTemplate *listTemplate = (CPListTemplate *)(CPTemplate *)(forms_cp->id_obj(obj_id)->object);
    listTemplate->delegate->listTemplateDidSelectListItem(listTemplate, (CPListItem *)(forms_cp->id_obj(item_id)->object), completion);
}

/*---------------------------------------------------------------------------*/

CPGridButton::CPGridButton(const char **titleVariants, unsigned titleVariantCount, CPImageSet *image, CPGridButtonHandler *handler)
{
    unsigned i;

    if (titleVariantCount != 0) {
        this->titleVariants = (char **)(malloc(titleVariantCount * sizeof(char *)));
        for (i = 0; i < titleVariantCount; i++) {
            this->titleVariants[i] = _strdup(titleVariants[i]);
        }
    }
    else {
        this->titleVariants = NULL;
    }
    this->titleVariantCount = titleVariantCount;
    this->image = image;
    this->handler = handler;
    enabled = true;
    for (i = 0; i < titleVariantCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_TITLE_VARIANT_ADD, forms_cp->obj_id, titleVariants[i] ? titleVariants[i] : "");
    }
    forms_cp->forms_async->enqueue(FORMS_CP_GRID_BUTTON_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), forms_cp->cp_obj_id(image));
}

CPGridButton::~CPGridButton()
{
    unsigned i;

    for (i = 0; i < titleVariantCount; i++) {
        if(titleVariants[i]) free(titleVariants[i]);
    }
    if (titleVariants) free(titleVariants);
    forms_cp->cp_free_id(this);
}

void CPGridButton::setEnabled(bool enabled)
{
    this->enabled = enabled;
    forms_cp->forms_async->enqueue(FORMS_CP_GRID_BUTTON_SET_ENABLED, forms_cp->cp_obj_id(this), enabled);
}

bool CPGridButton::isEnabled()
{
    return enabled;
}

void forms_cp_grid_button_handle(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    DBG_TRC(("forms_cp_grid_button_handle(%i)", obj_id));
    CPGridButton *gridButtons = (CPGridButton *)(forms_cp->id_obj(obj_id)->object);
    gridButtons->handler->gridButtonHandleSelection(gridButtons);
}

/*---------------------------------------------------------------------------*/

CPGridTemplate::CPGridTemplate(const char *title, CPGridButton **gridButtons, unsigned gridButtonCount)
{
    unsigned i;

    this->title = _strdup(title);
    if (gridButtonCount != 0) {
        this->gridButtons = (CPGridButton **)(malloc(gridButtonCount * sizeof(CPGridButton *)));
        memcpy(this->gridButtons, gridButtons, gridButtonCount * sizeof(CPGridButton *));
    }
    else {
        this->gridButtons = NULL;
    }
    this->gridButtonCount = gridButtonCount;
    for (i = 0; i < gridButtonCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_GRID_BUTTON_ADD, forms_cp->obj_id, forms_cp->cp_obj_id(gridButtons[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_GRID_TEMPLATE_CREATE, forms_cp->obj_id, forms_cp->cp_new_id((CPTemplate *) this), title ? title : "");
}

CPGridTemplate::~CPGridTemplate()
{
    if (title) free(title);
    if (gridButtons) free(gridButtons);
}

void CPGridTemplate::updateTitle(const char *title)
{
    if (this->title) free(this->title);
    this->title = _strdup(title);
    forms_cp->forms_async->enqueue(FORMS_CP_GRID_TEMPLATE_UPDATE_TITLE, forms_cp->cp_obj_id(this), title ? title : "");
}

void CPGridTemplate::updateGridButtons(CPGridButton **gridButtons, unsigned gridButtonCount)
{
    unsigned i, obj_id;

    free(this->gridButtons);
    this->gridButtons = (CPGridButton **)(malloc(gridButtonCount * sizeof(CPGridButton *)));
    memcpy(this->gridButtons, gridButtons, gridButtonCount * sizeof(CPGridButton *));
    this->gridButtonCount = gridButtonCount;
    obj_id = forms_cp->cp_obj_id(this);
    for (i = 0; i < gridButtonCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_GRID_BUTTON_ADD, obj_id, forms_cp->cp_obj_id(gridButtons[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_GRID_TEMPLATE_UPDATE_GRID_BUTTONS, obj_id);
}

/*---------------------------------------------------------------------------*/

CPAlertAction::CPAlertAction(const char *title, enum CPAlertActionStyle style, CPAlertActionHandler *handler)
{
    this->title = _strdup(title);
    this->style = style;
    this->handler = handler;
    forms_cp->forms_async->enqueue(FORMS_CP_ALERT_ACTION_CREATE, forms_cp->obj_id, forms_cp->cp_new_id(this), title ? title : "", style);
}

CPAlertAction::~CPAlertAction()
{
    if (title) free(title);
    forms_cp->cp_free_id(this);
}

void forms_cp_alert_action_handle(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    DBG_TRC(("forms_cp_alert_action_handle(%i)", obj_id));
    CPAlertAction *action = (CPAlertAction *)(forms_cp->id_obj(obj_id)->object);
    action->handler->alertActionHandleSelection(action);
}

/*---------------------------------------------------------------------------*/

CPAlertTemplate::CPAlertTemplate(const char **titleVariants, unsigned titleVariantCount, CPAlertAction **actions, unsigned actionCount)
{
    unsigned i;

    if (titleVariantCount != 0) {
        this->titleVariants = (char **)(malloc(titleVariantCount * sizeof(char *)));
        for (i = 0; i < titleVariantCount; i++) {
            this->titleVariants[i] = _strdup(titleVariants[i]);
        }
    }
    else {
        this->titleVariants = NULL;
    }
    if (actionCount != 0) {
        this->actions = (CPAlertAction **)(malloc(actionCount * sizeof(CPAlertAction *)));
        memcpy(this->actions, actions, actionCount * sizeof(CPAlertAction *));
    }
    else {
        this->actions = NULL;
    }
    this->actionCount = actionCount;
    for (i = 0; i < titleVariantCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_TITLE_VARIANT_ADD, forms_cp->obj_id, titleVariants[i] ? titleVariants[i] : "");
    }
    for (i = 0; i < actionCount; i++) {
        forms_cp->forms_async->enqueue(FORMS_CP_ALERT_ACTION_ADD, forms_cp->obj_id, forms_cp->cp_obj_id(actions[i]));
    }
    forms_cp->forms_async->enqueue(FORMS_CP_ALERT_TEMPLATE_CREATE, forms_cp->obj_id, forms_cp->cp_new_id((CPTemplate *) this));
}

CPAlertTemplate::~CPAlertTemplate()
{
    unsigned i;

    for (i = 0; i < titleVariantCount; i++) {
        if(titleVariants[i]) free(titleVariants[i]);
    }
    if (titleVariants) free(titleVariants);
    if (actions) free(actions);
}

/*---------------------------------------------------------------------------*/

class FormsCPInterfaceController : public forms_cp_object, public CPInterfaceController {
    int obj_id;
    unsigned templateSize;

public:
    FormsCPInterfaceController(int obj_id);
    ~FormsCPInterfaceController();
    void setDelegate(CPInterfaceControllerDelegate *Delegate);
    void setRootTemplate(CPTemplate *rootTemplate, bool animated);
    void pushTemplate(CPTemplate *templateToPush, bool animated);
    void popTemplate(bool animated);
    void popToRootTemplate(bool animated);
    void popToTemplate(CPTemplate *targetTemplate , bool animated);
    void presentTemplate(CPTemplate *templateToPresent , bool animated);
    void dismissTemplate(bool animated);
};

void FormsCPInterfaceController::setRootTemplate(CPTemplate *rootTemplate, bool animated)
{
    this->rootTemplate = rootTemplate;
    if (templateCount == 0) {
        topTemplate = rootTemplate;
        templates[0] = rootTemplate;
        templateCount = 1;
    }
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_SET_ROOT_TEMPLATE, obj_id, forms_cp->cp_obj_id(rootTemplate), animated);
}

void FormsCPInterfaceController::pushTemplate(CPTemplate *templateToPush, bool animated)
{
    topTemplate = templateToPush;
    if (templateCount == templateSize) {
        CPTemplate **t = (CPTemplate **)(malloc(2 * templateSize * sizeof(CPTemplate *)));
        memcpy(t, templates, templateSize * sizeof(CPTemplate *));
        free(templates);
        templates = t;
        templateSize *= 2;
    }
    templates[templateCount] = templateToPush;
    templateCount++;
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_PUSH_TEMPLATE, obj_id, forms_cp->cp_obj_id(templateToPush), animated);
}

void FormsCPInterfaceController::popTemplate(bool animated)
{
    if (templateCount > 1) {
        templateCount--;
        topTemplate = templates[templateCount - 1];
    }
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_POP_TEMPLATE, obj_id, animated);
}

void FormsCPInterfaceController::popToRootTemplate(bool animated)
{
    topTemplate = rootTemplate;
    templateCount = 1;
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_POP_TO_ROOT_TEMPLATE, obj_id, animated);
}

void FormsCPInterfaceController::popToTemplate(CPTemplate *targetTemplate , bool animated)
{
    unsigned i;

    i = 0;
    while ((i < templateCount) && (templates[i] != targetTemplate)) {
        i++;
    }
    if (i < templateCount) {
        templateCount = i + 1;
        topTemplate = targetTemplate;
    }
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_POP_TO_TEMPLATE, obj_id, forms_cp->cp_obj_id(targetTemplate), animated);
}

void FormsCPInterfaceController::presentTemplate(CPTemplate *templateToPresent , bool animated)
{
    presentedTemplate = templateToPresent;
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_PRESENT_TEMPLATE, obj_id, forms_cp->cp_obj_id(templateToPresent), animated);
}

void FormsCPInterfaceController::dismissTemplate(bool animated)
{
    presentedTemplate = NULL;
    forms_cp->forms_async->enqueue(FORMS_CP_INTERFACE_CONTROLLER_DISMISS_TEMPLATE, obj_id, animated);
}

void forms_cp_template_will_appear(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    int template_id = async_event->get_int();
    bool animated = async_event->get_bool();
    DBG_TRC(("forms_cp_template_will_appear(%i) %i %i", obj_id, template_id, animated));
    ((FormsCPInterfaceController *)(forms_cp->get_id_obj(obj_id)))->delegate->templateWillAppear((CPTemplate *)(forms_cp->id_obj(template_id)->object), animated);
}

void forms_cp_template_did_appear(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    int template_id = async_event->get_int();
    bool animated = async_event->get_bool();
    DBG_TRC(("forms_cp_template_did_appear(%i) %i %i", obj_id, template_id, animated));
    ((FormsCPInterfaceController *)(forms_cp->get_id_obj(obj_id)))->delegate->templateDidAppear((CPTemplate *)(forms_cp->id_obj(template_id)->object), animated);
}

void forms_cp_template_will_disappear(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    int template_id = async_event->get_int();
    bool animated = async_event->get_bool();
    DBG_TRC(("forms_cp_template_will_disappear(%i) %i %i", obj_id, template_id, animated));
    ((FormsCPInterfaceController *)(forms_cp->get_id_obj(obj_id)))->delegate->templateWillDisappear((CPTemplate *)(forms_cp->id_obj(template_id)->object), animated);
}

void forms_cp_template_did_disappear(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    int template_id = async_event->get_int();
    bool animated = async_event->get_bool();
    DBG_TRC(("forms_cp_template_did_disappear(%i) %i %i", obj_id, template_id, animated));
    ((FormsCPInterfaceController *)(forms_cp->get_id_obj(obj_id)))->delegate->templateDidDisappear((CPTemplate *)(forms_cp->id_obj(template_id)->object), animated);
}

FormsCPInterfaceController::FormsCPInterfaceController(int obj_id) :
    forms_cp_object(this)
{
    this->obj_id = obj_id;
    presentedTemplate = NULL;
    rootTemplate = NULL;
    topTemplate = NULL;
    templateSize = 16;
    templates = (CPTemplate **)(malloc(templateSize * sizeof(CPTemplate *)));
    templateCount = 0;
    delegate = NULL;
    forms_cp->set_id_obj(obj_id, this);
}

FormsCPInterfaceController::~FormsCPInterfaceController()
{
    forms_cp->forms_async->enqueue(FORMS_ASYNC_DELETE_OBJECT, obj_id);
    forms_cp->set_id_obj(obj_id, NULL);
    free(templates);
}

/*---------------------------------------------------------------------------*/

async_forms_cp::async_forms_cp(class async_forms *async_forms) :
    forms_cp_object(NULL)
{
    this->async_forms = async_forms;
    forms_async = async_forms->forms_async;
    forms_cp = this;
    tree = NULL;
    obj_id = new_id(this);
}

void async_forms_cp::use(CPApplicationDelegate *user)
{
    this->user = user;
    forms_async->enqueue(FORMS_CP_CREATE, async_forms->obj_id, obj_id);
}

void forms_cp_did_connect_car_interface_controller(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    DBG_TRC(("forms_cp_did_connect_car_interface_controller(%i)", obj_id));
    FormsCPInterfaceController *interfaceController = new FormsCPInterfaceController(obj_id);
    forms_cp->user->didConnectCarInterfaceController(interfaceController);
}

void forms_cp_did_disconnect_car_interface_controller(class async_event *async_event)
{
    int obj_id = async_event->get_int();
    DBG_TRC(("forms_cp_did_disconnect_car_interface_controller(%i)", obj_id));
    FormsCPInterfaceController *interfaceController = (FormsCPInterfaceController *)(forms_cp->get_id_obj(obj_id));
    forms_cp->user->didDisconnectCarInterfaceController(interfaceController);
    delete interfaceController;
}

int async_forms_cp::cp_new_id(void *object)
{
    forms_cp_object *forms_object = new forms_cp_object(object);
    forms_object->obj_id = new_id(forms_object);
    tree = tree->btree_put(forms_object);
    return (forms_object->obj_id);
}

void async_forms_cp::cp_free_id(void *object)
{
    forms_cp_object *forms_object = (forms_cp_object *)(tree->btree_find(object));
    forms_cp->forms_async->enqueue(FORMS_ASYNC_DESTROY_OBJECT, forms_object->obj_id);
    tree = tree->btree_get(forms_object);
    forms_object->object = NULL;
}

int async_forms_cp::cp_obj_id(void *object)
{
    return(((forms_cp_object *)(tree->btree_find(object)))->obj_id);
}

/*---------------------------------------------------------------------------*/

void forms_cp_delete_object         (class async_event *async_event)
{
    int obj_id = async_event->get_int();
    DBG_TRC(("forms_cp_delete_object(%i)", obj_id));
    delete forms_cp->id_obj(obj_id);
    forms_cp->free_id(obj_id);
}

void CarPlay::Use(CPApplicationDelegate *user)
{
    forms_cp->use(user);
    DBG_TRC(("CarPlay::Use(%i) ...", forms_cp->obj_id));
}

/*---------------------------------------------------------------------------*/
