ToolTalk ユーザーズガイド

ファイル内の特定の仕様の照会

ファイル内の特定の仕様を照会するためにフィルタ関数を作成し、対象とする仕様を取得します。

tt_file_objects_query を使って、指定されたファイル内のすべてのオブジェクトを見つけます。ToolTalk サービスは、各オブジェクトを見つけるとフィルタ関数を呼び出し、そのオブジェクトの objid とアプリケーションが与えた 2 つのポインタをそのフィルタ関数に渡します。フィルタ関数は演算をいくつか行い、Tt_filter_action の値 (TT_FILTER_CONTINUE または TT_FILTER_STOP) を返します。これは照会を続行するか、検出を終了してすぐに復帰するかを示します。

例 12–1 は、仕様リストの取得方法を示します。


例 12–1 仕様リストの取得

/*
 * Called to update the scrolling list of objects for a file. Uses
 * tt_file_objects_query to find all the ToolTalk objects.
 */
int
cntl_update_obj_panel()
{
       static int list_item = 0;
	char *file;
	int i;

	cntl_objid = (char *)0;

	for (i = list_item; i >= 0; i--) {
		xv_set(cntl_ui_olist, PANEL_LIST_DELETE, i, NULL);
	}

	list_item = 0;
	file = (char *)xv_get(cntl_ui_file_field, PANEL_VALUE);
	if (tt_file_objects_query(file,
                                     (Tt_filter_function)cntl_gather_specs,
                                   &list_item, NULL) != TT_OK) {
		xv_set(cntl_ui_base_window, FRAME_LEFT_FOOTER,
		       “Couldn't query objects for file”, NULL);
		return 0;
	}

	return 1;
}


tt_file_objects_query 関数内では、アプリケーションは、オブジェクトをスクロールリストに挿入するフィルタ関数 cntl_gather_specs を呼び出します。例 12–2 に objid の挿入方法を示します。


例 12–2 objid の挿入

/*
 * Function to insert the objid given into the scrolling lists of objects
 * for a file. Used inside tt_file_objects_query as it iterates through
 * all the ToolTalk objects in a file.
 */
Tt_filter_action
cntl_gather_specs(objid, list_count, acc)
     char *objid;
     void *list_count;
     void *acc;
{
	int *i = (int *)list_count;

	xv_set(cntl_ui_olist, PANEL_LIST_INSERT, *i,
	       PANEL_LIST_STRING, *i, objid,
	       NULL);

	*i = (*i + 1);

	/* continue processing */
	return TT_FILTER_CONTINUE;
}