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

NAMESPACE_BEGIN

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

#define ENUM_FORMS_CP_ASYNC_HANDLER\
    FORMS_CP_CREATE,\
    FORMS_CP_UI_IMAGE_CREATE,\
    FORMS_CP_IMAGE_SET_CREATE,\
    FORMS_CP_COMPLETION_COMPLETE,\
    FORMS_CP_LIST_ITEM_CREATE,\
    FORMS_CP_LIST_ITEM_WITH_IMAGE_CREATE,\
    FORMS_CP_LIST_ITEM_SET_TEXT,\
    FORMS_CP_LIST_ITEM_SET_DETAIL_TEXT,\
    FORMS_CP_LIST_ITEM_SET_IMAGE,\
    FORMS_CP_LIST_ITEM_ADD,\
    FORMS_CP_LIST_SECTION_CREATE,\
    FORMS_CP_LIST_SECTION_ADD,\
    FORMS_CP_LIST_TEMPLATE_CREATE,\
    FORMS_CP_LIST_TEMPLATE_UPDATE_SECTIONS,\
    FORMS_CP_TITLE_VARIANT_ADD,\
    FORMS_CP_GRID_BUTTON_CREATE,\
    FORMS_CP_GRID_BUTTON_SET_ENABLED,\
    FORMS_CP_GRID_BUTTON_ADD,\
    FORMS_CP_GRID_TEMPLATE_CREATE,\
    FORMS_CP_GRID_TEMPLATE_UPDATE_TITLE,\
    FORMS_CP_GRID_TEMPLATE_UPDATE_GRID_BUTTONS,\
    FORMS_CP_ALERT_ACTION_CREATE,\
    FORMS_CP_ALERT_ACTION_ADD,\
    FORMS_CP_ALERT_TEMPLATE_CREATE,\
    FORMS_CP_INTERFACE_CONTROLLER_SET_ROOT_TEMPLATE,\
    FORMS_CP_INTERFACE_CONTROLLER_PUSH_TEMPLATE,\
    FORMS_CP_INTERFACE_CONTROLLER_POP_TEMPLATE,\
    FORMS_CP_INTERFACE_CONTROLLER_POP_TO_ROOT_TEMPLATE,\
    FORMS_CP_INTERFACE_CONTROLLER_POP_TO_TEMPLATE,\
    FORMS_CP_INTERFACE_CONTROLLER_PRESENT_TEMPLATE,\
    FORMS_CP_INTERFACE_CONTROLLER_DISMISS_TEMPLATE,\

#define ENUM_FORMS_CP_ASYNC_JNI_DESC   ENUM_FORMS_CP_ASYNC_HANDLER

#define DEFINE_FORMS_CP_ASYNC_HANDLER\
    { "forms_cp_create",                "II",     0 },\
    { "forms_cp_ui_image_create",       "IIB",    0 },\
    { "forms_cp_image_set_create",      "IIBB",   0 },\
    { "forms_cp_completion_complete",   "I",      0 },\
    { "forms_cp_list_item_create",      "IIAA",   0 },\
    { "forms_cp_list_item_with_image_create","IIAAI",  0 },\
    { "forms_cp_list_item_set_text",    "IA",     0 },\
    { "forms_cp_list_item_set_detail_text","IA",  0 },\
    { "forms_cp_list_item_set_image",   "II",     0 },\
    { "forms_cp_list_item_add",         "II",     0 },\
    { "forms_cp_list_section_create",   "IIAA",   0 },\
    { "forms_cp_list_section_add",      "II",     0 },\
    { "forms_cp_list_template_create",  "IIA",    0 },\
    { "forms_cp_list_template_update_sections","I",      0 },\
    { "forms_cp_title_variant_add",     "IA",     0 },\
    { "forms_cp_grid_button_create",    "III",    0 },\
    { "forms_cp_grid_button_set_enabled","IZ",     0 },\
    { "forms_cp_grid_button_add",       "II",     0 },\
    { "forms_cp_grid_template_create",  "IIA",    0 },\
    { "forms_cp_grid_template_update_title","IA",     0 },\
    { "forms_cp_grid_template_update_grid_buttons","I",      0 },\
    { "forms_cp_alert_action_create",   "IIAI",   0 },\
    { "forms_cp_alert_action_add",      "II",     0 },\
    { "forms_cp_alert_template_create", "II",     0 },\
    { "forms_cp_interface_controller_set_root_template","IIZ",    0 },\
    { "forms_cp_interface_controller_push_template","IIZ",    0 },\
    { "forms_cp_interface_controller_pop_template","IZ",     0 },\
    { "forms_cp_interface_controller_pop_to_root_template","IZ",     0 },\
    { "forms_cp_interface_controller_pop_to_template","IIZ",    0 },\
    { "forms_cp_interface_controller_present_template","IIZ",    0 },\
    { "forms_cp_interface_controller_dismiss_template","IZ",     0 },\

#define DEFINE_FORMS_CP_ASYNC_JNI_DESC DEFINE_FORMS_CP_ASYNC_HANDLER

#define ENUM_FORMS_CP_EVENT_HANDLER\
    FORMS_CP_DELETE_OBJECT,\
    FORMS_CP_DID_CONNECT_CAR_INTERFACE_CONTROLLER,\
    FORMS_CP_DID_DISCONNECT_CAR_INTERFACE_CONTROLLER,\
    FORMS_CP_TEMPLATE_WILL_APPEAR,\
    FORMS_CP_TEMPLATE_DID_APPEAR,\
    FORMS_CP_TEMPLATE_WILL_DISAPPEAR,\
    FORMS_CP_TEMPLATE_DID_DISAPPEAR,\
    FORMS_CP_LIST_TEMPLATE_DID_SELECT_LIST_ITEM,\
    FORMS_CP_GRID_BUTTON_HANDLE,\
    FORMS_CP_ALERT_ACTION_HANDLE,\

/*---------------------------------------------------------------------------*/
#if defined(__cplusplus)

void forms_cp_delete_object         (class async_event *async_event);
void forms_cp_did_connect_car_interface_controller(class async_event *async_event);
void forms_cp_did_disconnect_car_interface_controller(class async_event *async_event);
void forms_cp_template_will_appear  (class async_event *async_event);
void forms_cp_template_did_appear   (class async_event *async_event);
void forms_cp_template_will_disappear(class async_event *async_event);
void forms_cp_template_did_disappear(class async_event *async_event);
void forms_cp_list_template_did_select_list_item(class async_event *async_event);
void forms_cp_grid_button_handle    (class async_event *async_event);
void forms_cp_alert_action_handle   (class async_event *async_event);

#define DEFINE_FORMS_CP_EVENT_HANDLER\
    { forms_cp_delete_object,         "I"},\
    { forms_cp_did_connect_car_interface_controller,"I"},\
    { forms_cp_did_disconnect_car_interface_controller,"I"},\
    { forms_cp_template_will_appear,  "IIZ"},\
    { forms_cp_template_did_appear,   "IIZ"},\
    { forms_cp_template_will_disappear,"IIZ"},\
    { forms_cp_template_did_disappear,"IIZ"},\
    { forms_cp_list_template_did_select_list_item,"III"},\
    { forms_cp_grid_button_handle,    "I"},\
    { forms_cp_alert_action_handle,   "I"},\

#define DEFINE_FORMS_CP_EVENT_JNI_DESC\
    { &FORMS_CP_DELETE_OBJECT,         forms_cp_delete_object,         "I"},\
    { &FORMS_CP_DID_CONNECT_CAR_INTERFACE_CONTROLLER,forms_cp_did_connect_car_interface_controller,"I"},\
    { &FORMS_CP_DID_DISCONNECT_CAR_INTERFACE_CONTROLLER,forms_cp_did_disconnect_car_interface_controller,"I"},\
    { &FORMS_CP_TEMPLATE_WILL_APPEAR,  forms_cp_template_will_appear,  "IIZ"},\
    { &FORMS_CP_TEMPLATE_DID_APPEAR,   forms_cp_template_did_appear,   "IIZ"},\
    { &FORMS_CP_TEMPLATE_WILL_DISAPPEAR,forms_cp_template_will_disappear,"IIZ"},\
    { &FORMS_CP_TEMPLATE_DID_DISAPPEAR,forms_cp_template_did_disappear,"IIZ"},\
    { &FORMS_CP_LIST_TEMPLATE_DID_SELECT_LIST_ITEM,forms_cp_list_template_did_select_list_item,"III"},\
    { &FORMS_CP_GRID_BUTTON_HANDLE,    forms_cp_grid_button_handle,    "I"},\
    { &FORMS_CP_ALERT_ACTION_HANDLE,   forms_cp_alert_action_handle,   "I"},\

class forms_cp_object : public btree {
public:
    void *object;
    int obj_id;

    forms_cp_object(void *object) { this->object = object; };

    int btree_compare(void * key) { return ((key > object) ? 1 : ((key < object) ? -1 : 0)); };
    int btree_compare(class btree * b) { return ((((class forms_cp_object *)b)->object > object) ? 1 : ((((class forms_cp_object *)b)->object < object) ? -1 : 0)); };
};

class async_forms_cp : public forms_cp_object {
    class async_forms *async_forms;
public:
    class forms_async *forms_async;
    class CPApplicationDelegate *user;
    class btree * tree;

    async_forms_cp(class async_forms *async_forms);

    int new_id(forms_cp_object *obj) { return async_forms->new_id((forms_object *)obj); }
    void free_id(int obj_id) { async_forms->free_id(obj_id); }
    forms_cp_object *id_obj(int obj_id)  { return((forms_cp_object *)(async_forms->id_obj(obj_id))); }
    void set_id_obj(int obj_id, forms_cp_object *obj) { async_forms->set_id_obj(obj_id, (forms_object *)obj); }
    forms_cp_object *get_id_obj(int obj_id) { return((forms_cp_object *)(async_forms->get_id_obj(obj_id))); }
    int cp_new_id(void *object);
    void cp_free_id(void *object);
    int cp_obj_id(void *object);

    void use(class CPApplicationDelegate *user);
};

#endif /* defined(__cplusplus) */
/*---------------------------------------------------------------------------*/

NAMESPACE_END
