This description assumes knowledge of the HadronZoo Database (HDB), the Delta Server (DS), and the ADP (Application Delta Profile). Please see the HadronZoo library manual, section 5. Programs that use the DS must call DeltaInit() as part of the initialization sequence. This call must take place AFTER data model construction is complete (all repositories declared and initialized), and BEFORE data transactions commence. This function calls ReadConfigDS() in order to establish the following:- The primary objective is to verify the ADP. If the application is new (of a hitherto unknown appname), the ADP is simply accepted. This is safe if the config read succeeded as this proves the data model (from which the ADP is compiled), is viable. On ADP acceptance, the ADP description is written to a standard location, usually /etc/hzDelta/. On subsequent runs the ADP description is compared to that stored in /etc/hzDelta/. The two ADP descriptions will be identical if there has been no change to the data model since the last run. If the data model has changed the ADP descriptions will not match. The new ADP can contain entities that do not exist in the old, and can omit entities that do exists in the old. However where the entity exists in both, the two ADPs must exactly agree on every detail of the entity. The program terminates if this comparison fails. Note that ADP comparison does not involve the DS. Once the comparison succeeeds, if the application is delta enabled, the next step is to seek a connection to the DS. While the DS is intended to be omnipresent, if it isn't up this function will return E_OK, allowing the application to go into service without the DS. Applications will not necessarily be delta enabled. It is standard practice for them not to be during development. Enabling a program for DS operation is a matter of adding a note to this effect in the configs. Not all applications will expect to receive deltas from sister applications on other machines. Those that do must add a DS handler and port, to the hzIpServer singleton. Note that the DS reads ADP descriptions from the standard location. The ADP description used to be passed to the DS by the application. This is no longer the practice. Arguments: None
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbADP::DeltaInit | (void) |
Declared in file: hzDatabase.h
Defined in file : hdbADP.cpp
Function Logic:
Function body:
hzEcode hdbADP::DeltaInit (void)
{
// Category: System
//
// This description assumes knowledge of the HadronZoo Database (HDB), the Delta Server (DS), and the ADP (Application Delta Profile). Please see the HadronZoo library manual,
// section 5.
//
// Programs that use the DS must call DeltaInit() as part of the initialization sequence. This call must take place AFTER data model construction is complete (all repositories
// declared and initialized), and BEFORE data transactions commence.
//
// This function calls ReadConfigDS() in order to establish the following:-
//
//
// The primary objective is to verify the ADP. If the application is new (of a hitherto unknown appname), the ADP is simply accepted. This is safe if the config read succeeded
// as this proves the data model (from which the ADP is compiled), is viable. On ADP acceptance, the ADP description is written to a standard location, usually /etc/hzDelta/.
//
// On subsequent runs the ADP description is compared to that stored in /etc/hzDelta/. The two ADP descriptions will be identical if there has been no change to the data model
// since the last run. If the data model has changed the ADP descriptions will not match. The new ADP can contain entities that do not exist in the old, and can omit entities
// that do exists in the old. However where the entity exists in both, the two ADPs must exactly agree on every detail of the entity. The program terminates if this comparison
// fails.
//
// Note that ADP comparison does not involve the DS. Once the comparison succeeeds, if the application is delta enabled, the next step is to seek a connection to the DS. While
// the DS is intended to be omnipresent, if it isn't up this function will return E_OK, allowing the application to go into service without the DS.
//
// Applications will not necessarily be delta enabled. It is standard practice for them not to be during development. Enabling a program for DS operation is a matter of adding
// a note to this effect in the configs. Not all applications will expect to receive deltas from sister applications on other machines. Those that do must add a DS handler and
// port, to the hzIpServer singleton.
//
// Note that the DS reads ADP descriptions from the standard location. The ADP description used to be passed to the DS by the application. This is no longer the practice.
//
// Arguments: None
//
// Returns: E_ARGUMENT If one or more arguments is null or invalid
// E_INITFAIL If there is currently no hostname and none could be established
// E_FORMAT If there is the application profile held in /ect/hzDelta.d/ is not of the expected form
// E_OPENFAIL If this function cannot write out the application's version of the profile
// E_OK If a connection to a delta server was established or if bMustHave is false
_hzfunc("hdbADP::DeltaInit") ;
static bool bBeenHere = false ;
uint32_t nIndex ; // Server iterator
hzEcode rc = E_OK ; // Return code
if (!m_appName)
return hzerr(E_SEQUENCE, "No application name") ;
if (bBeenHere)
return hzerr(E_SEQUENCE, "Repeat call") ;
// Establish hostname of this machine
if (!_hzGlobal_Hostname)
{
if (SetupHost() != E_OK)
hzexit(E_INITFAIL, "Could not setup hostname") ;
if (!_hzGlobal_Hostname)
hzexit(E_INITFAIL, "No hostname established") ;
}
// Check that application configs have defined at least one data class and repository
if (!CountDataClass())
return hzerr(E_NODATA, "No Data Clases defined") ;
if (!CountObjRepos())
return hzerr(E_NODATA, "No Data Repositories defined") ;
// Read the DS config to obtain delta cluster info and to find the appID as used by the DS
rc = ReadConfigDS() ;
if (rc != E_OK)
return rc ;
/*
** ** DS servers and apps now listsed. Can set m_nDeltaID and if applicable, init connection to DS
** */
for (nIndex = 0; nIndex < 4; nIndex++)
{
if (s_DS_Hosts[nIndex] == _hzGlobal_Hostname)
{
threadLog("Local Machine is member of the delta cluster\n") ;
break ;
}
}
if (s_DS_Addrs[nIndex] != _hzGlobal_nullIP && s_DS_Ports[nIndex])
{
threadLog("Local Machine is delta active\n") ;
m_nDeltaID = s_mapDS_AppsByName[m_appName] ;
}
if (!m_nDeltaID)
{
threadLog("This app (%s) is NOT delta active\n", *m_appName) ;
return E_OK ;
}
m_eDeltaMode = DELTA_MODE_AUTH ;
// Connect to DS as client
SOCKADDRUN svrAddr ; // Address of Local DS
// Create the socket
memset(&svrAddr, 0,sizeof(svrAddr)) ;
svrAddr.sun_family = AF_UNIX ;
strcpy(svrAddr.sun_path, "/home/deltasvr/DS.unix.socket") ;
if ((m_unixSock = socket(AF_UNIX, SOCK_STREAM, 0))<&eq; 0)
return hzerr(E_NOSOCKET, "Could not create DS socket (returns %d, errno %d)") ;
threadLog("DS: Using socket %d\n", m_unixSock) ;
// Connect stage
if (connect(m_unixSock, (struct sockaddr *) &svrAddr, sizeof(svrAddr)) < 0)
return hzerr(E_HOSTFAIL, "Could not connect to DS (errno=%d)", errno) ;
return E_OK ;
}