srv_connect(), dp4_srv_connect()

Purpose

Obtains a connection to the DP4 database manager on a named machine

Syntax (CCOWN)

int srv_connect(const char * server_name);

Syntax (DP4DBAPI)

int srv_connect(const char * server_name)
CONN * dp4_srv_connect(dp4_name_string server_name,int nr_system,int rw_access,dp4_error_callback error_handler,int channel,void * reserved);

Parameters

const char * server_name

Name of server to connect to. This parameter is ignored if DP4 is loaded in a configuration that does not support named connections. For this reason you may wish to access the @net_status table to check the connection type in the @resil_type field after calling srv_enable() to finish initialisation of the connection.

 

int nr_system

Number system to be used by applications. This should be N_C for C or C++ applications

 

int rw_access

Desired access level. Read access is in bits 0 to 7,write access in bits 8 to 15. 0 gives minimum access. -1 gives full access to any databases opened (255 for both read and write access).

 

dp4_error_callback error_handler

Pointer to function to be used to raise errors. See definition of dp4_error_callback to see how to define such a function or consult the source module ccsrvcal.c (in the src subdirectory of each DP4 version on the DP4 CD ROM). If the error callback function is not required then pass 0. In this case the calling application must call dp4_error_status() after each call a dp4 function, and take appropriate action if an error has occured. The source code of dp4dbase.cpp gives an example of how to do this.

 

int channel

Internal IPC channel to use. A C program or an ADC should pass the DP4 global app_ipc_channel for this. Other programs should pass 0.

 

void * reserved

Used by the "traditional" DP4 C library to pass a pointer to a structure containing pointers to all the DP4 global variables used by the database API. Pass 0.

Description

The srv_connect() functions establish a connection to a named server if DP4 is loaded in a configuration that supports named connections, or to the local database manager otherwise. (Named connections are supported on Win32, Linux, and Unix releases of DP4 when the TCP network requester is loaded and AUXDISTR is not used.)

Normally you would not call dp4_srv_connect()function directly. It will be wrapped by a higher level function. For C, the srv_connect() function is the wrapper.

After a sucessful call to dp4_srv_connect() you must call srv_enable() or srv_enable_ex() to perform additional initialisations for the connection.

The srv_connect() function will not return an error value if you attempt to connect to a named server when DP4 is not loaded in a configuration that supports named connections. If your program needs to detect this situation then you should fetch the network status record of the connection after it has opened successfully, and check that the connection is a network connection. See Creating Named Connections from C/C++ Code in the Guide to DP4 Networking for more information.

Return values

srv_connect() returns a positive value if successful, also assigned to df_process, or -1 otherwise. dp4_srv_connect() returns a connection handle if successful or NULL (0) otherwise.

See also

srv_enable(), srv_disable(), srv_end_process(), Error handling with DP4DBAPI