Assignment 1 - Part 1 Flashcards
gfclient_download.c
main file for the client workload generator.
Illustrates use of gfclient library, how the API is intended to be used
user code of gfclient. This possible means that it uses the gfclient.c
function pointers in C
are callbacks
Use cases
- Function pointer can be used in place of switch case.
- consider the following C program where wrapper() receives a void fun() as parameter and calls the passed function.
void A() { printf("I am function A\n"); }
void B(void (*ptr)()) { (*ptr) (); // callback to A }
int main() { void (*ptr)() = &A;
// calling function B and passing // address of the function A as argument B(ptr);
return 0;
}
opaque pointer
meaning that it should be defined within the gfclient.c file and no user code (e.g. gfclient_download.c) should ever do anything with the object besides pass it to functions in the gfclient library.
Opaque pointers are a way to hide the implementation details of an interface from ordinary clients, so that the implementation may be changed without the need to recompile the modules using it.
gfc_set_writearg
the user can register an argument that should be passed to the callback on every call with this function
Sets the third argument for all calls to the registered write callback
gfc_set_headerarg
the user can register an argument that should be passed to the callback on every call with this function
Sets the third argument for all calls to the registered header callback
pointer registered with gfc_set_headerarg