/* $Revision: 1.5 $ */
/*  
 *  cv_sfinterface.h
 *
 *	Routines to interface with cv.dll by way of function pointers 
 *  locally stored.
 */

#ifndef __cv_sfinterface__
#define __cv_sfinterface__


#include <stdio.h>


/******************************************************************************
 *							OLD ENUMERATIONS						          *
 ******************************************************************************/

/* 
 * Most state decisions are coded only once, as needed.  The
 * following enumeration identifies these decisions.  Since 
 * these decisions occur only once per state it is not necessary
 * to differentiate multiple occrences.  
 */

typedef enum {
	UNKNOWM_MISC_CALL = 0,
	ACTIVE_ON_ENTRY,
	ENTER_FROM_TRANSITION,
	INACTIVE_CHILDREN,
	INACTIVE_PARENT,
	INACTIVE_PARENT_AFTER_ENTRY,
	INACTIVE_PARENT_AFTER_SIB_ENTRY,
	INACTIVE_AFTER_ENTRY_EVENT,
	ENTER_FROM_OUTSIDE,
	PREV_ACTIVE_CHILD,
	HIST_CHILD_CALL,
	INACTIVE_AFTER_CHILD_ENTRY,
	INACTIVE_CHILD_FROM_HIST,
	ENTER_SET_FROM_OUTSIDE,
	INACTIVE_AFTER_DEFAULT,
	INACTIVE_BEFORE_DURING,
	INACTIVE_CHILDREN_DURING,
	ACTIVE_CHILD_CALL,
	INACTIVE_BEFORE_EXIT,
	ACTIVE_CHILD_AT_EXIT,
	ACTIVE_CHILD_EXIT,
	INACTIVE_AFTER_CHILD_EXIT
} CvStateDecisionType;


typedef enum {
	TRIGGER_CONDITION,
	GUARD_CONDITION
} CvTransitionConditionType;


typedef enum {
	MISCELLANEOUS_DECISION = -1,
	UNKNOWN_REPEAT_TYPE = 0,
	ON_EVENT_TEST,
	INACTIVE_FROM_BROADCAST,
	ACTIVE_CHILD_FROM_BROADCAST,
	INACTIVE_FROM_CHILD_ENTRY
} CvRepeatableDecisionType;

#define NUM_REPEAT_TYPES 4

/******************************************************************************/


typedef struct CvSfInterfaceInfoStruct {
	bool covEnabled;
	
	int (*transInitFcn)		 (unsigned int cvId, 
		                          bool isConditional);

	int (*stateInitFcn)		 (unsigned int cvId, 
								  unsigned int numChild, 
								  bool hasDuringSwitch,
								  bool hasExitSwitch,
								  bool hasHistSwitch);

	int (*chartInitFcn)		 (unsigned int cvId, 
								  unsigned int numChild, 
								  bool hasDuringSwitch,
								  bool hasExitSwitch,
								  bool hasHistSwitch);

	int (*genUpdateFcn)		 (unsigned int cvId,
								  unsigned int objectIndex,
								  unsigned int retValue);

} CvSfInterfaceInfo;


/*
 * Gateway Functions
 */

extern void cv_init_trans(unsigned int cvId, 
		                  bool isConditional);

extern void cv_init_state(unsigned int cvId, 
						  unsigned int numChild, 
						  bool hasDuringSwitch,
						  bool hasExitSwitch,
						  bool hasHistSwitch);

extern void cv_init_chart(unsigned int cvId, 
						  unsigned int numChild, 
						  bool hasDuringSwitch,
						  bool hasExitSwitch,
						  bool hasHistSwitch);

extern void cv_update_call(unsigned int cvId,
						   unsigned int objectIndex,
						   unsigned int retValue);

/*
 * Initialization Functions
 */
extern void cv_create_interface(const char *machName);
extern void cv_destroy_interface(void);
extern void cv_create_instance_objects(unsigned int *states, 
							    unsigned int stateCount,
								unsigned int *transitions,
								unsigned int transCount,
								unsigned int *chartId,
								unsigned int chartSfId, 
								const char *fullPath);

/* Opaque type */
typedef struct SfDebugInstanceStruct DBInstanceStruct;


extern void sf_debug_cv_initialize_instance(DBInstanceStruct *debugInstance,
									 unsigned int machineNumber,
									 unsigned int chartNumber,
									 unsigned int instanceNumber);

extern void sf_debug_cv_terminate_chart(DBInstanceStruct *debugInstance,
									unsigned int machineNumber,
									unsigned int chartNumber);


extern bool cv_is_enabled(void);


/* Obsolete functions needed for compiling only */
extern void cv_call_trans_test(unsigned int id, unsigned int value, unsigned int codeInstance);
extern void cv_call_sub_cond_test(unsigned int id, unsigned int value, unsigned int index, CvTransitionConditionType condType);

#endif
