| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbADP::DeltaInit | (const char*,const char*,const char*,const char*,bool,) |
Declared in file: hzDatabase.h
Defined in file : hzDelta.cpp
Function Logic:
Function body:
hzEcode hdbADP::DeltaInit (const char* dir, const char* app, const char* arg, const char* ver, bool bMustHave)
{
_hzfunc("hzDeltaClient::DeltaInit") ;
static bool bBeenHere = false ;
const hdbObjRepos* pRepos ;
ofstream os ;
FSTAT fs ;
hzDocXml X ;
hzChain Z ;
hzAttrset ai ;
hzXmlNode* pRoot ;
hzXmlNode* pN ;
const char* anam ;
const char* aval ;
hzString adpFile ;
hzString pathname ;
hzString portNote ;
hzString portApps ;
hzIpaddr ipa ;
uint32_t nIndex ;
uint32_t nPort ;
hzEcode rc = E_OK ;
if (bBeenHere)
return hzerr(E_SEQUENCE, "Repeat call") ;
if (!dir || !dir[0]){ rc = E_ARGUMENT ; Z << "No application profile directory supplied\n" ; }
if (!app || !app[0]){ rc = E_ARGUMENT ; Z << "No application profile appname supplied\n" ; }
if (!arg || !arg[0]){ rc = E_ARGUMENT ; Z << "No application profile argument supplied\n" ; }
if (!ver || !ver[0]){ rc = E_ARGUMENT ; Z << "No application profile version supplied\n" ; }
if (Z.Size())
{ rc = E_ARGUMENT ; portNote = Z ; hzerr(rc, *portNote) ; return rc ; }
if (!_hzGlobal_Hostname)
{
if (SetupHost() != E_OK)
hzexit(E_INITFAIL, "Could not setup hostname") ;
if (!_hzGlobal_Hostname)
hzexit(E_INITFAIL, "No hostname established") ;
}
if (!CountDataClass())
return hzerr(E_NODATA, "No Data Clases defined") ;
if (!CountObjRepos())
return hzerr(E_NODATA, "No Data Repositories defined") ;
/*
** ** Read the delta config to obtain delta connection info
** */
if (lstat(s_deltaConf, &fs) < 0)
{
if (bMustHave)
return hzerr(E_NOTFOUND, "Delta config file %s not found\n", *s_deltaConf) ;
return E_OK ;
}
rc = X.Load(s_deltaConf) ;
if (rc != E_OK)
return hzerr(rc, "Could not open conf file (%s)\n", *s_deltaConf) ;
pRoot = X.GetRoot() ;
if (!pRoot->NameEQ("deltaCluster"))
return hzerr(rc, "No root <deltaCluster> tag in conf file (%s)\n", *s_deltaConf) ;
for (pN = pRoot->GetFirstChild() ; pN ; pN = pN->Sibling())
{
if (pN->NameEQ("pointA")) nIndex = 0;
else if (pN->NameEQ("pointB")) nIndex = 1;
else if (pN->NameEQ("pointC")) nIndex = 2;
else if (pN->NameEQ("pointD")) nIndex = 3;
else
return hzerr(E_FORMAT, "Illegal tag <%s> in <deltaCluster>. Only <pointA/B/C/D> allowed\n", pN->txtName()) ;
for (ai = pN ; ai.Valid() ; ai.Advance())
{
anam = ai.Name() ; aval = ai.Value() ;
if (!strcmp(anam, "addr")) ipa = aval ;
else if (!strcmp(anam, "portNote")) portNote = aval ;
else if (!strcmp(anam, "portApps")) portApps = aval ;
else
return hzerr(E_FORMAT, "Line %d: Illegal attribute %s. Only addr|portNote|portApps allowed", pN->Line(), anam) ;
}
if (ipa == _hzGlobal_nullIP)
return hzerr(E_FORMAT, "Line %d: Invalid IP address\n", pN->Line()) ;
if (!portNote) return hzerr(E_FORMAT, "Line %d: 2nd attribute of <%s> must be 'portNote'\n", pN->Line(), pN->txtName()) ;
if (!portApps) return hzerr(E_FORMAT, "Line %d: 3rd attribute of <%s> must be 'portApps'\n", pN->Line(), pN->txtName()) ;
nPort = atoi(*portNote) ;
if (ipa == _hzGlobal_livehost)
s_deltaPort_in = nPort ;
nPort = atoi(*portApps) ;
if (ipa == _hzGlobal_livehost)
s_deltaPort = nPort ;
}
/*
** ** Read the application delta profile
** */
Z.Printf("%s/%s.%s.%s.xml", dir, app, arg, ver) ;
pathname = Z ;
Z.Clear() ;
Z.Printf("<appProfile appname="%s" arg="%s" ver="%s">\n" , app, arg, ver) ;
for (nIndex = 0; nIndex < CountObjRepos() ; nIndex++)
{
pRepos = GetObjRepos(nIndex) ;
pRepos->DescRepos(Z, 1);
}
Z << "</appProfile>\n" ;
os.open(*pathname) ;
if (os.fail())
return hzerr(E_OPENFAIL, "Cannot stat application profile [%s]", *pathname) ;
os << Z ;
os.close() ;
/*
** ** Obtain a Delta Client instance and call Connect
** */
hzDeltaClient::GetInstance() ;
_hzGlobal_DeltaClient->InitOnce(pathname) ;
rc = _hzGlobal_DeltaClient->Connect() ;
if (rc != E_OK && bMustHave)
return rc ;
return E_OK ;
}