import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'

The **GW2RegisterAnalysisMemory** registers the memory location to store a analysis report to a session. Using this function activates the Analysis Process for the *Session*.

<Tabs>

<TabItem value="C++" label="C++" default>

**Synopsis**

The **GW2RegisterAnalysisMemory** function stores in the object pointed to by **analysisFileBuffer** a pointer to the analysis report produced by a successful run of API function **runSession** that used session **session**. The size of the analysis report, in bytes, is placed in the object pointed to by **analysisLength**. The format of the analysis report will be in the format requested by **format**. Using this function activates the Analysis Process Mode for the session.

```cpp

#include "glasswall.core2.api.h"

int GW2RegisterAnalysisMemory(Session session,
                              char **analysisFileBuffer,
                              size_t analysisLength,
                              Analysis_format format);
```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.


**Example**

```cpp

#include "glasswall.core2.api.h"

Session_Handle session;
char *analysisReport = NULL;
size_t analysisReportSize = 0;

session = GW2OpenSession();

if (!session)
    /* deal with error */
else
{
    if (GW2RegisterAnalysisMemory(session, &analysisReport, &analysisReportSize, PF_XML) < 0)
        /* deal with error */
    else
        /* analysisReport points to the analysis report data */
}

/* later */
if (GW2CloseSession(session) < 0)
    /* error closing session */
```

</TabItem>

<TabItem value="C#" label="C#">

**Synopsis**

```csharp
public int RegisterAnalysisMemory(
    int session,
    out IntPtr analysisBufferPtr,
    ref UIntPtr analysisBufferLengthPtr,
    int Format)

```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

<TabItem value="Java" label="Java">

**Synopsis**

```java
import com.glasswall.core2javabridge.*;

public int GW2RegisterAnalysisMemory(int session, int format) throws GlasswallException
```

**Description**

The **GW2RegisterAnalysisMemory** function registers a memory buffer as the output for the analysis report, for the session specified by `session`. Call **GetAnalysisBuffer** or **GetAnalysisReport** after having called **GW2RunSession** in order to retrieve the analysis report.

Refer to API Overview/Return types for valid enumerators for `format`.

**Returns**

The **GW2RegisterAnalysisMemory** function returns a **GW2_RetStatus** enumeration converted to `int`. The value will be negative if an error occurred. `0` indicates success. Refer to the API Overview/Return types for details. 

A **GlasswallException** exception will be thrown if `session` is invalid.

**Synopsis - Retrieve Data**

```java
import com.glasswall.core2javabridge.*;

public byte[] GetAnalysisBuffer(int session) throws GlasswallException
public String GetAnalysisReport(int session) throws GlasswallException
```

**Description**

The **GetAnalysisBuffer** function retrieves the contents of the analysis report buffer associated with the session specified by `session`.

**Returns**

The **GetAnalysisBuffer** function returns a `Byte[]` containing the analysis report. The **GetAnalysisReport** function returns a `String` containing the analysis report. These will be null if both **GW2RunSession** and **GW2RegisterAnalysisMemory** have not been called.

A **GlasswallException** exception will be thrown if `session` is invalid.

</TabItem>

<TabItem value="Python" label="Python">

**Synopsis**

Registers an analysis file for the given session. The analysis file will be created during the session's run_session call.

```py
def register_analysis(self, session: int, output_file: Optional[str] = None):
    """ Registers an analysis file for the given session. The analysis file will be created during the session's run_session call.

    Args:
        session (int): The session integer.
        output_file (Optional[str]): Default None. The file path where the analysis will be written. None returns the analysis as bytes.

    Returns:
        gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'status', 'session', 'analysis_format'. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size. If output_file is not None (file mode) 'output_file' is included.
    """
```

**Returns**

gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'status', 'session', 'analysis_format'. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size. If output_file is not None (file mode) 'output_file' is included.

The status attribute is an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

<TabItem value="JavaScript" label="JavaScript">

**Synopsis**

This function stores a pointer to the analysis report produced by a successful run of runSession.

```jsx

/**
 *
 * @param {number} session The ID of the session.
 * @param {string} analysisFileBuffer The pointer to the location of the analysis report.
 * @param {number} analysisOutputLength The size of the analysis report.
 * @param {number} format The specified format.
 */

GW2RegisterAnalysisMemory(
    session,
    analysisFileBuffer,
    analysisOutputLength,
    format)

```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

</Tabs>