Return TypeFunction nameArguments
hzEcodehdbADP::DeltaInit(const char*,const char*,const char*,const char*,bool,)

Declared in file: hzDatabase.h
Defined in file : hzDelta.cpp

Function Logic:

0:START 1:bBeenHere 2:Return hzerr(E_SEQUENCE,Repeat call) 3:!dir||!dir[0] 4:rc items 5:!app||!app[0] 6:rc items 7:!arg||!arg[0] 8:rc items 9:!ver||!ver[0] 10:rc items hzChain::Size 11:Z.Size() 12:rc portNote 13:Return rc 14:!_hzGlobal_Hostname 15:SetupHost()!=E_OK 16:hzexit 17:!_hzGlobal_Hostname 18:hzexit 19:!CountDataClass() 20:Return hzerr(E_NODATA,No Data Clases defined) 21:!CountObjRepos() 22:Return hzerr(E_NODATA,No Data Repositories defined) 23:lstat(s_deltaConf,&fs)<0 24:bMustHave 25:Return hzerr(E_NOTFOUND,Delta config file %s not found\n,*s_deltaConf) 26:Return E_OK 27:hzDocXml::Load rc 28:rc!=E_OK 29:Return hzerr(rc,Could not open conf file (%s)\n,*s_deltaConf) 30:hzDocXml::GetRoot pRoot hzXmlNode::NameEQ 31:!pRoot->NameEQ(deltaCluster) 32:Return hzerr(rc,No root tag in conf file (%s)\n,*s_deltaConf) 33:pN; 34:pN->NameEQ(pointA) 35:nIndex hzXmlNode::NameEQ 36:pN->NameEQ(pointB) 37:nIndex hzXmlNode::NameEQ 38:pN->NameEQ(pointC) 39:nIndex hzXmlNode::NameEQ 40:pN->NameEQ(pointD) 41:nIndex 42:Return hzerr(E_FORMAT,Illegal tag <%s> in . Only allowed\n,pN->txtName()) 43:ai.Valid(); 44:hzAttrset::Name anam hzAttrset::Value aval strcmp 45:!strcmp(anam,addr) 46:ipa strcmp 47:!strcmp(anam,portNote) 48:portNote strcmp 49:!strcmp(anam,portApps) 50:portApps 51:Return hzerr(E_FORMAT,Line %d: Illegal attribute %s. Only addr|portNote|portApps allowed,pN->Line(),anam) 52:ipa==_hzGlobal_nullIP 53:Return hzerr(E_FORMAT,Line %d: Invalid IP address\n,pN->Line()) 54:!portNote 55:Return hzerr(E_FORMAT,Line %d: 2nd attribute of <%s> must be 'portNote'\n,pN->Line(),pN->txtName()) 56:!portApps 57:Return hzerr(E_FORMAT,Line %d: 3rd attribute of <%s> must be 'portApps'\n,pN->Line(),pN->txtName()) 58:atoi nPort 59:ipa==_hzGlobal_livehost 60:s_deltaPort_in 61:atoi nPort 62:ipa==_hzGlobal_livehost 63:s_deltaPort 64:hzChain::Printf pathname hzChain::Clear hzChain::Printf nIndex 65:nIndex 66:hdbADP::GetObjRepos pRepos hdbObjRepos::DescRepos 67:items ofstream::open ofstream::fail 68:os.fail() 69:Return hzerr(E_OPENFAIL,Cannot stat application profile [%s],*pathname) 70:items close hzDeltaClient::GetInstance hzDeltaClient::InitOnce hzDeltaClient::Connect rc 71:rc!=E_OK&&bMustHave 72:Return rc 73:Return E_OK

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 ;
}