+void CheckResult( FILE *p_res ) {
+ char psz_resp[9];
+
+ fscanf( p_res, "%8s", &psz_resp );
+ if( IsFailure( psz_resp ) ) {
+ printf( " failed\n" );
+ exit( -1 );
+ }
+}
+
+void CheckedCommand( FILE *p_cmd, FILE *p_res, char *p_format, ... ) {
+ va_list ap;
+ va_start( ap, p_format );
+
+ vfprintf( p_cmd, p_format, ap );
+ fflush( p_cmd );
+ if( p_res != NULL ) {
+ CheckResult( p_res );
+ }
+ va_end( ap );
+}
+
+int GenImage( FILE *p_cmd, FILE *p_res ) {
+ int i_overlay;
+
+ printf( "Getting an overlay..." );
+ CheckedCommand( p_cmd, p_res, "GenImage\n" );
+ fscanf( p_res, "%d", &i_overlay );
+ printf( " done. Overlay is %d\n", i_overlay );
+
+ return i_overlay;
+}
+
+void DeleteImage( FILE *p_cmd, FILE *p_res, int i_overlay ) {
+ printf( "Removing image..." );
+ CheckedCommand( p_cmd, p_res, "DeleteImage %d\n", i_overlay );
+ printf( " done\n" );
+}
+
+void StartAtomic( FILE *p_cmd, FILE *p_res ) {
+ CheckedCommand( p_cmd, p_res, "StartAtomic\n" );
+}
+
+void EndAtomic( FILE *p_cmd, FILE *p_res ) {
+ CheckedCommand( p_cmd, p_res, "EndAtomic\n" );
+}
+
+void DataSharedMem( FILE *p_cmd, FILE *p_res, int i_overlay, int i_width,
+ int i_height, char *psz_format, int i_shmid ) {
+
+ printf( "Sending data via shared memory..." );
+ CheckedCommand( p_cmd, p_res, "DataSharedMem %d %d %d %s %d\n", i_overlay,
+ i_width, i_height, psz_format, i_shmid );
+ printf( " done\n" );
+}
+
+void SetAlpha( FILE *p_cmd, FILE *p_res, int i_overlay, int i_alpha ) {
+ CheckedCommand( p_cmd, p_res, "SetAlpha %d %d\n", i_overlay, i_alpha );
+}
+
+void SetPosition( FILE *p_cmd, FILE *p_res, int i_overlay, int i_x, int i_y ) {
+ CheckedCommand( p_cmd, p_res, "SetPosition %d %d %d\n", i_overlay, i_x,
+ i_y );
+}
+
+void SetVisibility( FILE *p_cmd, FILE *p_res, int i_overlay, int i_visible ) {
+ CheckedCommand( p_cmd, p_res, "SetVisibility %d %d\n", i_overlay,
+ i_visible );
+}
+
+/*****************************************************************************
+ * Test Routines
+ *****************************************************************************/
+
+void BasicTest( FILE *p_cmd, FILE *p_res, int i_overlay ) {
+ printf( "Activating overlay..." );
+ SetVisibility( p_cmd, p_res, i_overlay, 1 );
+ printf( " done\n" );
+
+ printf( "Sweeping alpha..." );
+ for( int i_alpha = 0xFF; i_alpha >= -0xFF ; i_alpha -= 8 ) {
+ SetAlpha( p_cmd, p_res, i_overlay, abs( i_alpha ) );
+ usleep( 20000 );
+ }
+ SetAlpha( p_cmd, p_res, i_overlay, 255 );
+ printf( " done\n" );
+
+ printf( "Circle motion..." );
+ for( float f_theta = 0; f_theta <= 2 * M_PI ; f_theta += M_PI / 64.0 ) {
+ SetPosition( p_cmd, p_res, i_overlay,
+ (int)( - cos( f_theta ) * 100.0 + 100.0 ),
+ (int)( - sin( f_theta ) * 100.0 + 100.0 ) );
+ usleep( 20000 );
+ }
+ SetPosition( p_cmd, p_res, i_overlay, 0, 100 );
+ printf( " done\n" );
+
+ printf( "Atomic motion..." );
+ StartAtomic( p_cmd, p_res );
+ SetPosition( p_cmd, NULL, i_overlay, 200, 50 );
+ sleep( 1 );
+ SetPosition( p_cmd, NULL, i_overlay, 0, 0 );
+ EndAtomic( p_cmd, p_res );
+ CheckResult( p_res );
+ CheckResult( p_res );
+ printf( " done\n" );
+
+ sleep( 5 );
+}
+