{"title":"Initialize the library","category":"default","creationDate":1776961627,"content":"<p>Before the library can be used, you must initialize it with the <code>init_library<\/code> function.<\/p>\n<div class=\"sc-notice note\"><div>\n<p>The call and the callback are asynchronous to prevent the call from blocking the calling thread.<\/p>\n<\/div><\/div>\n<h2 id=\"implement-the-callback\">Implement the callback<\/h2>\n<p>Implement the <code>initialization_CB<\/code>\u00a0and pass this as a parameter of the <code>init_library<\/code> call. For more information on how to do this, see <a href=\"\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/calls-and-callbacks-c-library\/implement-callbacks\">Implement callbacks<\/a>.<\/p>\n<h3 id=\"parameters\">Parameters<\/h3>\n<table style=\"width:100%;\"><colgroup><col style=\"width: 8%\"><col style=\"width: 91%\"><\/colgroup><thead><tr class=\"header\"><th>Name<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\n<p><code>result<\/code><\/p>\n<\/td><td>\n<p>Returns the result of initializing the library. The result of initialization is always zero.<\/p>\n<\/td><\/tr><tr><td>\n<p><code>echo_struct<\/code><\/p>\n<\/td><td>\n<p>A pointer to a user-defined struct that is echoed back in the callback. Use this to share a POS data struct between the call to the library and the callback from the library.<\/p>\n<\/td><\/tr><\/tbody><\/table>\n<h3 id=\"code-example\">Code example<\/h3>\n<pre><code class=\"language-cpp\">void initialization_CB(void *result, void *echo_struct){app_context_t * POS = (app_context_t *)echo_struct;\nprintf(\"library is initialized\");\n}<\/code><\/pre>\n<h2 id=\"allocate-request-structure\">Allocate request structure<\/h2>\n<p>Use <code>init_library_allocate<\/code> to allocate memory for an <code>init_library_request<\/code> structure. Populate the <code>init_library_request<\/code> by performing string duplication to fill heap-allocated strings.\u00a0\u00a0The library automatically frees this memory.<\/p>\n<h2 id=\"call-the-init_library-function\">Call the init_library function<\/h2>\n<p>Call the <code>init_library<\/code> function with the provided parameters to initialize the library.<\/p>\n<h3 id=\"parameters-1\">Parameters<\/h3>\n<table style=\"width:100%;\"><colgroup><col style=\"width: 12%\"><col style=\"width: 0%\"><col style=\"width: 0%\"><col style=\"width: 87%\"><\/colgroup><thead><tr class=\"header\"><th>Name<\/th><th>Type<\/th><th>Required<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\n<p><code>initReq<\/code><\/p>\n<\/td><td>\n<p>Struct: <a href=\"\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/structs\/init_library_request\">init_library_request<\/a><\/p>\n<\/td><td>\n<p><img title=\"-white_check_mark-\" alt=\"-white_check_mark-\" class=\"smileys\" src=\"\/user\/data\/smileys\/emoji\/white_check_mark.png\" \/><\/p>\n<\/td><td>\n<p>A pointer to the <code>init_library_request<\/code> struct, this struct contains all the input parameters for this call. Allocate this request with init_library_allocate.<\/p>\n<\/td><\/tr><tr><td>\n<p><code>initialization_CB<\/code><\/p>\n<\/td><td>\n<p>Function<\/p>\n<\/td><td>\n<p><img title=\"-white_check_mark-\" alt=\"-white_check_mark-\" class=\"smileys\" src=\"\/user\/data\/smileys\/emoji\/white_check_mark.png\" \/><\/p>\n<\/td><td>\n<p>A pointer to the callback function in the POS that the system returns with the results of the initialization call.<\/p>\n<\/td><\/tr><tr><td>\n<p><code>echo_struct<\/code><\/p>\n<\/td><td>\n<p>Struct: <a href=\"\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/structs\/echo_struct\">echo_struct<\/a><\/p>\n<\/td><td>\n<p><img title=\"-white_check_mark-\" alt=\"-white_check_mark-\" class=\"smileys\" src=\"\/user\/data\/smileys\/emoji\/white_check_mark.png\" \/><\/p>\n<\/td><td>\n<p>A pointer to a POS-defined struct that is echoed back in the callback. Use this to share a POS data struct between the call to the library and the callback from the library.<\/p>\n<\/td><\/tr><\/tbody><\/table>\n<h2 id=\"get-the-function-call-result\">Get the function call result<\/h2>\n<p><code>ADYLibraryResult<\/code> is used to store the result of the function call, the immediate response to the call. This is an enum that indicates if the system received the request. Should be <code>ADYEN_OK<\/code>, if this is not the case, something has gone wrong. In this case, check the input to the call and if it cannot be resolved, log the result and contact\u00a0<a href=\"https:\/\/ca-test.adyen.com\/ca\/ca\/contactUs\/support.shtml?form=other\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Support Team<\/a><\/p>\n<div class=\"sc-notice note\"><div>\n<p>This is not the final result of the call. The library returns the final result in response to the library initialization call.<\/p>\n<\/div><\/div>\n<h2 id=\"handle-the-callback\">Handle the callback<\/h2>\n<p>The POS needs to wait for the initialization callback before continuing with other functions, like boarding the POS systems and PED devices, and performing transactions.<\/p>\n<h3 id=\"parameters-2\">Parameters<\/h3>\n<table style=\"width:100%;\"><colgroup><col style=\"width: 8%\"><col style=\"width: 91%\"><\/colgroup><thead><tr class=\"header\"><th>Name<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\n<p><code>result<\/code><\/p>\n<\/td><td>\n<p>Returns the result of initializing the library. The result of initialization is always zero.<\/p>\n<\/td><\/tr><tr><td>\n<p><code>echo_struct<\/code><\/p>\n<\/td><td>\n<p>A pointer to a user-defined struct that is echoed back in the callback. Use this to share a POS data struct between the call to the library and the callback from the library.<\/p>\n<\/td><\/tr><\/tbody><\/table>\n<h2 id=\"code-example-1\">Code example<\/h2>\n<pre><code class=\"language-cpp\">typedef struct {\n  char *user_data;\n} app_context_t;\n\n\/\/ result is always null for initialization callback\nvoid initialization_CB(void *result, void *echo_struct) {\napp_context_t * POS = (app_context_t *)echo_struct;\nprintf(\"library is initialized\");\n}\n\nmain()\n{\n  app_context_t POS;\n    init_library_request *initReq = init_library_allocate();\n    initReq-&gt;pos_name = strdup(\"Adyen\");\n    initReq-&gt;app_name = strdup(\"Adyen\");\n    .\n    .\n    .\n    ADYLibraryResult result = init_library(initReq, initialization_CB, &amp;POS);\n}<\/code><\/pre>","url":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/key-steps-c-library\/initialize-the-library-c-library","articleFields":{"id":"24217493","type":"page","_expandable":{"operations":""},"status":"current"},"algolia":{"url":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/key-steps-c-library\/initialize-the-library-c-library","title":"Initialize the library","content":"Before the library can be used, you must initialize it with the init_library function.\n\nThe call and the callback are asynchronous to prevent the call from blocking the calling thread.\n\nImplement the callback\nImplement the initialization_CB\u00a0and pass this as a parameter of the init_library call. For more information on how to do this, see Implement callbacks.\nParameters\nNameDescription\nresult\n\nReturns the result of initializing the library. The result of initialization is always zero.\n\necho_struct\n\nA pointer to a user-defined struct that is echoed back in the callback. Use this to share a POS data struct between the call to the library and the callback from the library.\n\nCode example\nvoid initialization_CB(void *result, void *echo_struct){app_context_t * POS = (app_context_t *)echo_struct;\nprintf(\"library is initialized\");\n}\nAllocate request structure\nUse init_library_allocate to allocate memory for an init_library_request structure. Populate the init_library_request by performing string duplication to fill heap-allocated strings.\u00a0\u00a0The library automatically frees this memory.\nCall the init_library function\nCall the init_library function with the provided parameters to initialize the library.\nParameters\nNameTypeRequiredDescription\ninitReq\n\nStruct: init_library_request\n\n\n\nA pointer to the init_library_request struct, this struct contains all the input parameters for this call. Allocate this request with init_library_allocate.\n\ninitialization_CB\n\nFunction\n\n\n\nA pointer to the callback function in the POS that the system returns with the results of the initialization call.\n\necho_struct\n\nStruct: echo_struct\n\n\n\nA pointer to a POS-defined struct that is echoed back in the callback. Use this to share a POS data struct between the call to the library and the callback from the library.\n\nGet the function call result\nADYLibraryResult is used to store the result of the function call, the immediate response to the call. This is an enum that indicates if the system received the request. Should be ADYEN_OK, if this is not the case, something has gone wrong. In this case, check the input to the call and if it cannot be resolved, log the result and contact\u00a0Support Team\n\nThis is not the final result of the call. The library returns the final result in response to the library initialization call.\n\nHandle the callback\nThe POS needs to wait for the initialization callback before continuing with other functions, like boarding the POS systems and PED devices, and performing transactions.\nParameters\nNameDescription\nresult\n\nReturns the result of initializing the library. The result of initialization is always zero.\n\necho_struct\n\nA pointer to a user-defined struct that is echoed back in the callback. Use this to share a POS data struct between the call to the library and the callback from the library.\n\nCode example\ntypedef struct {\n  char *user_data;\n} app_context_t;\n\n\/\/ result is always null for initialization callback\nvoid initialization_CB(void *result, void *echo_struct) {\napp_context_t * POS = (app_context_t *)echo_struct;\nprintf(\"library is initialized\");\n}\n\nmain()\n{\n  app_context_t POS;\n    init_library_request *initReq = init_library_allocate();\n    initReq-&gt;pos_name = strdup(\"Adyen\");\n    initReq-&gt;app_name = strdup(\"Adyen\");\n    .\n    .\n    .\n    ADYLibraryResult result = init_library(initReq, initialization_CB, &amp;POS);\n}","type":"page","locale":"pt","boost":14,"hierarchy":{"lvl0":"Home","lvl1":"Terminais","lvl2":"Deprecation of classic libraries","lvl3":"Library integrations","lvl4":"C library integration","lvl5":"Key steps","lvl6":"Initialize the library"},"hierarchy_url":{"lvl0":"https:\/\/docs.adyen.com\/pt","lvl1":"https:\/\/docs.adyen.com\/pt\/point-of-sale","lvl2":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation","lvl3":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations","lvl4":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration","lvl5":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/key-steps-c-library","lvl6":"\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/key-steps-c-library\/initialize-the-library-c-library"},"levels":7,"category":"In-person payments","category_color":"green","tags":["Initialize","library"]}}
