static int write_main_session_restore( GenCodeInfo genCodeInfo, ABObj project ) { File codeFile; if (!genCodeInfo || !project) return (0); codeFile = genCodeInfo->code_file; if (abmfP_proj_needs_session_restore(project)) { AB_TRAVERSAL trav; ABObj action; char *ss_restore_CB_name = NULL; abio_puts(codeFile,"\n"); abio_puts(codeFile,"if (dtb_app_resource_rec.session_file)\n"); abio_puts(codeFile,"{\n"); if (!obj_is_project(project)) project = obj_get_project(project); /* * Search for session restore callback in project * action list */ for (trav_open(&trav, project, AB_TRAV_ACTIONS); (action = trav_next(&trav)) != NULL;) { switch(obj_get_when(action)) { case AB_WHEN_SESSION_RESTORE: /* * Remember session restore callback if found */ ss_restore_CB_name = obj_get_func_name(action); break; default: break; } } trav_close(&trav); abio_printf(codeFile, " dtb_set_client_session_restoreCB((DtbClientSessionRestoreCB)%s);\n", ss_restore_CB_name ? ss_restore_CB_name : "NULL"); abio_puts(codeFile, " (void)dtb_session_restore(toplevel, dtb_app_resource_rec.session_file);\n"); abio_puts(codeFile,"}\n"); abio_puts(codeFile,"\n"); } return (0); }
STRING abmfP_get_action_name(ABObj action) { static char name[256]; STRING parent_name = (STRING) NULL; ABObj from = NULL, parent = NULL; STRING tmpName = NULL; *name = 0; from = obj_get_from(action); if (action->info.action.auto_named && (from != NULL)) { /* If the source object is the project, * then this is an "Application" connection. * This probably won't happen because right * now "Application" connections can only be * of type AB_FUNC_USER_DEF (which means auto- * named is FALSE). */ if (obj_is_project(from)) { parent = obj_get_project(action); parent_name = (STRING) util_malloc( strlen(obj_get_name(parent)) + APP_PREFIX_LEN + 1); strcpy(parent_name, obj_get_name(parent)); strcat(parent_name, APP_PREFIX); } else { parent = obj_get_module(from); parent_name = obj_get_name(parent); } if (!util_strempty(parent_name) && !util_strempty(obj_get_name(from))) { sprintf(name, "%s_%s%s", parent_name, obj_get_name(from), obj_get_func_name_suffix(action)); } if (obj_is_project(from)) { util_free(parent_name); } } else { if ((tmpName = obj_get_func_name(action)) != NULL) { sprintf(name, "%s", tmpName); } } return (name[0] == 0 ? NULL : name); }
static int write_main_register_save_yourself( GenCodeInfo genCodeInfo, ABObj project, char *atom_name ) { File codeFile; if (!genCodeInfo || !project) return (0); if (!atom_name) atom_name = "save_yourself_atom"; codeFile = genCodeInfo->code_file; abio_puts(codeFile,"\n"); /* * Set client save session callback */ if (abmfP_proj_needs_session_save(project)) { AB_TRAVERSAL trav; ABObj action; char *ss_save_CB_name = NULL; /* * Search for session save callback in project * action list */ for (trav_open(&trav, project, AB_TRAV_ACTIONS); (action = trav_next(&trav)) != NULL;) { switch(obj_get_when(action)) { case AB_WHEN_SESSION_SAVE: /* * Remember session save callback if found */ ss_save_CB_name = obj_get_func_name(action); break; default: break; } } trav_close(&trav); abio_printf(codeFile, "dtb_set_client_session_saveCB((DtbClientSessionSaveCB)%s);\n", ss_save_CB_name ? ss_save_CB_name : "NULL"); abio_puts(codeFile, "\n"); } abio_printf(codeFile,"XmAddWMProtocolCallback(toplevel, %s,\n", atom_name); abio_puts(codeFile,"\tdtb_session_save, (XtPointer)NULL);\n"); abio_puts(codeFile,"\n"); return (0); }
static int write_main_tooltalk_init( GenCodeInfo genCodeInfo, ABObj project ) { AB_TOOLTALK_LEVEL tt_level; AB_TRAVERSAL trav; STRING vendor, version; ABObj action; File codeFile; int ret_val = 0; if (!genCodeInfo || !project || (tt_level = obj_get_tooltalk_level(project)) == AB_TOOLTALK_NONE) return 0; codeFile = genCodeInfo->code_file; abio_puts(codeFile, abmfP_comment_begin); abio_puts(codeFile, abmfP_comment_continue); abio_puts(codeFile, "Initialize ToolTalk to handle Desktop Message Protocol\n"); abio_puts(codeFile, abmfP_comment_end); if (tt_level == AB_TOOLTALK_DESKTOP_ADVANCED) { for (trav_open(&trav, project, AB_TRAV_ACTIONS); (action = trav_next(&trav)) != NULL;) { switch(obj_get_when(action)) { case AB_WHEN_TOOLTALK_QUIT: abio_printf(codeFile, "dtb_set_tt_msg_quitCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; case AB_WHEN_TOOLTALK_DO_COMMAND: abio_printf(codeFile, "dtb_set_tt_msg_do_commandCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; case AB_WHEN_TOOLTALK_GET_STATUS: abio_printf(codeFile, "dtb_set_tt_msg_get_statusCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; case AB_WHEN_TOOLTALK_PAUSE_RESUME: abio_printf(codeFile, "dtb_set_tt_msg_pause_resumeCB((DtbTTMsgHandlerCB)%s);\n", obj_get_func_name(action)); break; default: break; } } trav_close(&trav); abio_puts(codeFile, "\n"); } /* Write out tt init code to deal with possible remote display session */ abio_puts(codeFile, "ttenv = getenv(\"TT_SESSION\");\n"); abio_puts(codeFile, "if (!ttenv || strlen(ttenv) == 0)\n"); abio_indent(codeFile); abio_puts(codeFile,"ttenv = getenv(\"_SUN_TT_SESSION\");\n"); abio_outdent(codeFile); abio_puts(codeFile, "if (!ttenv || strlen(ttenv) == 0)\n"); abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "session = tt_X_session(XDisplayString(display));\n"); abio_puts(codeFile, "tt_default_session_set(session);\n"); abio_puts(codeFile, "tt_free(session);\n"); abmfP_write_c_block_end(genCodeInfo); abio_printf(codeFile, "tt_proc_id = ttdt_open(&tt_fd, \"%s\", ", obj_get_name(project)); vendor = obj_get_vendor(project); version = obj_get_version(project); abio_printf(codeFile, "\"%s\", \"%s\", 1);\n", vendor? vendor : "NULL", version? version : "NULL"); abio_puts(codeFile, "tt_status = tt_ptr_error(tt_proc_id);\n"); abio_puts(codeFile, "if (tt_status != TT_OK)\n"); /* abio_puts(codeFile, "{\n"); abio_indent(codeFile); */ abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "fprintf(stderr,\"ttdt_open(): %s\\n\", tt_status_message(tt_status));\n"); abio_puts(codeFile, "tt_proc_id = NULL;\n"); /* abio_outdent(codeFile); abio_puts(codeFile, "}\n"); */ abmfP_write_c_block_end(genCodeInfo); abio_puts(codeFile, "else\n"); /* abio_puts(codeFile, "{\n"); abio_indent(codeFile); */ abmfP_write_c_block_begin(genCodeInfo); abio_puts(codeFile, "XtAppAddInput(app, tt_fd, (XtPointer)XtInputReadMask,\n"); abio_indent(codeFile); abio_puts(codeFile, "tttk_Xt_input_handler, tt_proc_id);\n\n"); abio_outdent(codeFile); abio_printf(codeFile, "tt_session_pattern = ttdt_session_join(NULL, %s,\n", tt_level == AB_TOOLTALK_DESKTOP_ADVANCED? "dtb_tt_contractCB" : "NULL"); abio_indent(codeFile); abio_puts(codeFile, "toplevel, NULL, True);\n\n"); abio_outdent(codeFile); abio_puts(codeFile, "atexit(dtb_tt_close);\n"); /* abio_outdent(codeFile); abio_puts(codeFile, "}\n"); */ abmfP_write_c_block_end(genCodeInfo); return 0; }