Example a_backup/testing/cmiss_time_api: Using the C API to work with Cmiss_time and Cmiss_time_keeper.

This routine builds a program which links against the cmgui libraries to test time keeper and time object.


The comfile run by this example is as follows:

extern "C"
{
#include "api/cmiss_context.h"
#include "api/cmiss_status.h"
#include "api/cmiss_time.h"
#include "api/cmiss_time_keeper.h"
#include <gtk/gtk.h>
}
#include <iostream>
#include <sys/time.h>

using namespace std;

static int time_callback(Cmiss_time_notifier_id time_notifier, double current_time, void *user_data)
{	
	static int continue_flag = 9;
	if (current_time == 0.05 || current_time == 0.0)
	{
		continue_flag--;
	}

	static suseconds_t prev_tv_usec = -1;
	timeval time_v;

	if (continue_flag > 0)
	{
		if (gettimeofday(&time_v, 0))
		{
			cout << "Error: gettimeofday filed." << endl;
		}
		
		if (prev_tv_usec == -1) 
		{
			cout << "first call" << endl;
			cout << "Forward Loop mode" << endl;
		}

		cout << "Time_call_back time = " << current_time << endl;
		if (continue_flag == 4  && current_time == 0.05)
		{
			Cmiss_time_keeper_id time_keeper = 
				Cmiss_context_get_default_time_keeper((Cmiss_context_id)user_data);
			Cmiss_time_keeper_stop(time_keeper);
			Cmiss_time_notifier_regular_set_offset(time_notifier,0.0);
			Cmiss_time_keeper_set_attribute_real(time_keeper, CMISS_TIME_KEEPER_ATTRIBUTE_MINIMUM_TIME, -0.04);
			Cmiss_time_keeper_set_attribute_real(time_keeper, CMISS_TIME_KEEPER_ATTRIBUTE_MAXIMUM_TIME, 1.04);
			Cmiss_time_keeper_set_repeat_mode(time_keeper, CMISS_TIME_KEEPER_REPEAT_MODE_PLAY_SWING);
			Cmiss_time_keeper_play(time_keeper,CMISS_TIME_KEEPER_PLAY_FORWARD);
			cout << "Swing mode" << endl;
			Cmiss_time_keeper_destroy(&time_keeper);
		}
//  		else
//  		{
//  			suseconds_t elapsed_time = time_v.tv_usec - prev_tv_usec;
//  			if (elapsed_time < 0) elapsed_time += 1000000;
//  			{
//  				cout << " elapsed system time = ";
//  				cout.fill('0');
//  				cout.width(6);
//  				cout << right << elapsed_time << endl;
//  			}
//  		}	
		prev_tv_usec = time_v.tv_usec;
	}
	else
	{
		Cmiss_context_execute_command(
			(Cmiss_context_id)user_data, "quit");
	}
	return 1;
}

int main(int argc, char *argv[])
{
	Cmiss_context_id context = Cmiss_context_create("testing");
		gtk_parse_args(&argc, &argv);
	if (context && (CMISS_OK == Cmiss_context_enable_user_interface(context, NULL)))
	{

		Cmiss_time_keeper_id time_keeper = Cmiss_context_get_default_time_keeper(context);
		Cmiss_time_notifier_id time_notifier = Cmiss_time_keeper_create_notifier_regular(time_keeper, 10.0,0.0);
		Cmiss_time_notifier_add_callback(time_notifier,time_callback,(void*)context);
		Cmiss_time_keeper_set_attribute_real(time_keeper, CMISS_TIME_KEEPER_ATTRIBUTE_MINIMUM_TIME, 0.0);
		Cmiss_time_keeper_set_attribute_real(time_keeper, CMISS_TIME_KEEPER_ATTRIBUTE_MAXIMUM_TIME, 1.0);
		Cmiss_time_keeper_set_attribute_real(time_keeper, CMISS_TIME_KEEPER_ATTRIBUTE_SPEED, 1.0);
		Cmiss_time_notifier_regular_set_frequency(time_notifier, 10);
		Cmiss_time_notifier_regular_set_offset(time_notifier, 0.05);
		Cmiss_time_keeper_set_frame_mode(time_keeper, CMISS_TIME_KEEPER_FRAME_MODE_PLAY_EVERY_FRAME);
		enum Cmiss_time_keeper_frame_mode frame_mode;
		frame_mode = Cmiss_time_keeper_get_frame_mode(time_keeper);
		Cmiss_time_keeper_play(time_keeper,CMISS_TIME_KEEPER_PLAY_FORWARD);
		Cmiss_time_keeper_set_repeat_mode(time_keeper, CMISS_TIME_KEEPER_REPEAT_MODE_PLAY_LOOP);

		Cmiss_context_run_main_loop(context);
		Cmiss_time_keeper_stop(time_keeper);
		Cmiss_time_keeper_remove_time_notifier(time_keeper, time_notifier);
 		Cmiss_time_notifier_remove_callback(time_notifier,time_callback,(void*)context);
 		Cmiss_time_notifier_destroy(&time_notifier);
		Cmiss_time_keeper_destroy(&time_keeper);
		Cmiss_context_destroy(&context);
	}
}


Files used by this example are:

Name                Modified     Size

cmiss_time_api.cpp 20-Apr-2012 3.5k Makefile 20-Apr-2012 2.6k

Download the entire example:

Name                                             Modified     Size

examples_a_backup_testing_cmiss_time_api.tar.gz 12-Aug-2014 4.8k

Testing status by version:

StatusTestedReal time (s)
x86-linux
cmgui-gtk-debugFailureSun Mar 6 00:06:45 20160
last breakThu Aug 7 16:21:00 20140
last successFri Jan 11 00:17:00 20138

Testing status by file:


Html last generated: Sun Mar 6 05:51:01 2016

Input last modified: Fri Apr 20 16:02:11 2012


CMISS Help / Examples / a_backup / testing / cmiss_time_api