// file: $ISIP_BASE/util/demo/isip_comm_server_dialog_manager/isip_comm_dialog_manager.h
// version: $Id: isip_comm_dialog_navigation_mgr.h 10045 2005-05-06 20:53:45Z elliott $
//

/*-----------------------------------------------------------------------*
 *                                                                       *
 *		CSLR Communicator Dialogue Manager 		         * 
 *		Hub Dialog Server Main		   		         * 
 *                                                                       *
 *                                                                       *
 *   Wayne Ward (whw@cslr.colorado.edu)                              	 *
 *   Center for Spoken Language Research				 *
 *   University of Colorado at Boulder					 *
 *   (c) 1999 All Rights Reserved					 *
 *                                                                       *
 *-----------------------------------------------------------------------*/

#ifndef _ISIP_COMM_DIALOG_MANAGER_H
#define _ISIP_COMM_DIALOG_MANAGER_H

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <sys/wait.h>
#include <strings.h>
#include <math.h>

#include "pconf.h"
#include "parse.h"
#include "dm.h"
#include "dm_globals.h"
#include "task_globals.h"
#include "functionlib.h"

#define DEFAULT_AIRMODE "optimize_price"
#define MAJOR_DEBUG 1

//states of the server
#define GET_PROCESS_ID       0
#define WAIT_FOR_PARSE       5
#define WAIT_FOR_PARSE_ACK   6
#define WAIT_FOR_DB          10
#define WAIT_FOR_DB_ACK      11
#define PROCESSING_PARSE     12

//#define INITIAL_STATE        GET_PROCESS_ID
#define INITIAL_STATE        WAIT_FOR_PARSE

#define NO_RESPONSE_TIMEOUT 15000

#define SERVER_NAME_STRING "dialog navigation mgr"

// in parse.cc - dialog library functions
extern char     *dir;

/*
#define NL_QUE_LEN	10
typedef struct frame_que {
	Gal_Frame	frame;
	int		enable_input;
	void		*sd;
}FrameQue;
struct frame_que nl_que[NL_QUE_LEN];
*/

//char *ambiguity;
//char *ambiguity_choices;
//int  ambiguity_leg;   

//static char     voice[LABEL_LEN];

// This define is only used in isip_comm_dialog_navigation_mgr_func.cc
//
#define endl(lp) lp += strlen(lp)

// functions in isip_comm_dialog_navigation_mgr.cc
void no_response_from_user(void *server_data);
struct db_row *set_selection(aFrame *frame, int row);
void retry_query(void *server_data);
void log_session_end(void *server_data);
void get_col_info(int row, char *heading_name, char *out);
void nl_request(char *spch_act, char *prompt, char *task,
		int enable_input_after_prompt, void *server_data, char *voice);
int query_database(char *sql_query, aFrame *frame, void *server_data,
		    int access_web);
int process_db_result_Query_Distance(char *frame_name, char *question_type,
				     void *server_data);
int process_db_result_Query_Direction(char *frame_name, char *question_type,
				      void *server_data);
int process_db_result_Query_List(char *frame_name, char *question_type,
				 void *server_data);
int process_db_result_Query_Address(char *frame_name, char *question_type,
				    void *server_data);

// functions in dbq.cc
int build_dbq(char *dbp, aFrame *frame, void *server_data);

// function declarations in isip_comm_dialog_navigation_task.cc
void reset_task();
void merge_context(aFrame **context, aFrame **extracts);
int action_switch(void *server_data);
char *check_drive(aFrame **rframe);
void mask_slots(aFrame *cf, aFrame *ef);
char *check_query_generic(aFrame **rframe, char *query_name);

// functions in isip_comm_dialog_navigation_func.cc
void Reset_dm(char *frame_name, char *key, char *val);

// structs used in isip_comm_dialog_navigation_func.cc
struct x_fun {
  const char *name;
  void (*fun)(char *str);
};

struct s_fun {
  const char *name;
  void (*fun)(char *slot, char *token, char *val);
};

#endif
