Adding source code to the Circle DataBlade module udr.c file

You must add code to implement the Contains() function, which you can see in Visual C++ under the Globals node in the Class view. This function implements the same functionality as the rciContains() function in Exercise 4 and the Contains() function in Exercise 5.

Because the Contains() function in the Circle DataBlade module calls the Distance() function in the Point DataBlade module, you must include a wrapper function for the Distance() function in the Circle DataBlade module udr.c file. The Contains() function calls the wrapper function, which loads the Distance() function from the Point DataBlade module, executes it, and returns the result to the Contains() function.

To implement the Contains() function:

  1. Double-click Contains() in the Class view and scroll to the beginning of the udr.c file.
  2. Add the following wrapper function to the udr.c file for the Circle DataBlade module after the list of #include statements:
    mi_double_precision *Distance 
    ( MI_CONNECTION * Gen_Con, 
    Point * Pnt1,  
    Point * Pnt2 
    ) 
    { MI_FUNC_DESC * fd = NULL; 
    MI_DATUM ret = NULL; 
    mi_integer error = 0;  
    fd = mi_routine_get( Gen_Con, 0, "function Distance(Point, Point)"); 
    if (fd == NULL)
        DBDK_TRACE_ERROR( "Contains",
                "function Distance(Point, Point) not gotten.", 10 );
    
    ret = mi_routine_exec( Gen_Con, fd, &error, Pnt1, Pnt2); 
    if (error != MI_OK)
        DBDK_TRACE_ERROR( "Contains",
             "exec function Distance(Point, Point) failed.", 10 );  
    return ret; 
    } 
  3. Replace the statement Gen_Con = NULL; with the following connection statement:
    Gen_Con = mi_open( NULL, NULL, NULL );         
    /* Verify that the connection has been established. */         
    if( Gen_Con == 0 )         
    {                 
             /*
             ** Opening the current connection has failed      
             ** so issue the following message and quit.              
             **         
             **      "Connection has failed in Contains."         
             */        
             DBDK_TRACE_ERROR( "Contains", ERRORMESG1, 10 ); 
        
             /* not reached */         
    } 
  4. Replace the code between the comment /* Your_Code ... BEGIN*/ and the comment /*Your_Code ... END*/ with the following code:
    /*        
    ** Computes the distance between        
    ** the center of the circle and        
    ** the point.        
    */        
    {       
      double * dist = Distance( Gen_Con, Pnt1, &Circ1->center );         
      /* Is the distance within the radius? */         
      if( (*dist - Circ1->radius) <= 0 )         
      {            
            Gen_RetVal = 1;      
      }       
      else       
      {        
            Gen_RetVal = 0;      
      }       
    } 
  5. Check your source code against the final version of udr.c.
  6. Save the changes to udr.c

Copyright© 2019 HCL Technologies Limited