StartLineProcessConnector::~StartLineProcessConnector() {
    DDSDomainParticipant *participant = RTIConnector::getParticipant();
    DDS_ReturnCode_t retcode;


    if (NULL != m_reader_cache) {
        if (DDS_RETCODE_OK != RTIConnector::getSubscriber()->delete_datareader(m_reader_cache)) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Unable to delete m_reader_cache \n", LOG_LOCATION);
        }
        m_reader_cache = NULL;
    }
    if (NULL != m_read_topic) {
        if (DDS_RETCODE_OK != participant->delete_topic(m_read_topic)) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Unable to delete m_read_topic \n", LOG_LOCATION);
        }
        m_read_topic = NULL;
    }

    // Un-register the type...
    if ((NULL != participant) && (NULL != m_type_name_cache)) {
        retcode = MONITORING::leaseProcessStartTypeSupport::unregister_type(participant, m_type_name_cache);
        if (retcode != DDS_RETCODE_OK) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Error ---> RTCConnector() unregister_type RTC error \n", LOG_LOCATION);
        }
        m_type_name_cache = NULL;
    }
    pt_rtc = 0;

    return;
}
bool StartLineProcessConnector::createReader() {
    DDSSubscriber *subscriber = RTIConnector::getSubscriber();
    if(FAILURE==CControllerThread::getInstance()->CommandWriter("Monitoring_Library","psl_profile"))
    {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error ---> StartLineProcessConnector::CreateWriter Failure\n ", LOG_LOCATION);
    }
    if (NULL == m_read_topic) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error ---> StartLineProcessConnector::CreateReader() m_read_topic is NULL for RTC! \n ", LOG_LOCATION);

        return false;
    }

    if (NULL != m_reader_cache) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error ---> RTCConnector::CreateReader() m_reader_cache exists for RTC!\n  \n ", LOG_LOCATION);

        return false;
    }

    /* Create a data reader listener for cache */
    LineProcessStatusListener *m_reader_listener_cache = new LineProcessStatusListener();
    /* To customize the data reader QoS, use the configuration file USER_QOS_PROFILES.xml */

    m_reader_cache = subscriber->create_datareader_with_profile(m_read_topic, "Monitoring_Library", "Monitoring_Profile", m_reader_listener_cache,
            DDS_STATUS_MASK_ALL);

    if (m_reader_cache == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d)::CreateReader() error for RTC\n  \n ", LOG_LOCATION);
        delete m_reader_listener_cache;
        m_reader_listener_cache = NULL;
        return false;
    }
    g_cSystemLogger.LogMessage("(%s:%s:%d):: Create Reader sucess", LOG_LOCATION);

    return true;
}
StartLineProcessConnector::StartLineProcessConnector(const char* rd_topic) {
    DDS_ReturnCode_t retcode_cache;
    DDSDomainParticipant *participant = RTIConnector::getParticipant();
    m_read_topic = NULL;
    pt_rtc = NULL;
    m_reader_cache = NULL;

    if (rd_topic == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->rd_topic is NULL \n", LOG_LOCATION);
        return;
    }
    if (participant == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->Participant is NULL \n", LOG_LOCATION);
        return;
    }

    /* Register the type before creating the topic for RTC */
    m_type_name_cache = MONITORING::leaseProcessStartTypeSupport::get_type_name();
    retcode_cache = MONITORING::leaseProcessStartTypeSupport::register_type(participant, m_type_name_cache);
    if (retcode_cache != DDS_RETCODE_OK) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->Register Type RTC ERROR \n", LOG_LOCATION);
        m_type_name_cache = NULL;
        return;
    }
    if (NULL == m_read_topic) {
        /* To customize the topic QoS, use the configuration file USER_QOS_PROFILES.xml */
        m_read_topic = participant->create_topic(rd_topic, m_type_name_cache, DDS_TOPIC_QOS_DEFAULT, NULL /* listener */
                , DDS_STATUS_MASK_NONE);
        if (m_read_topic == NULL) {
            g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->create topic success is NULL \n", LOG_LOCATION);
            return;
        }
    }
    g_cSystemLogger.LogMessage("(%s:%s:%d)::  --->create topic success \n", LOG_LOCATION);

}
bool StartLineProcessCollector::collect(MONITORING::leaseProcessStart *sample, StartLineProcessConnector *conn) {

    if (NULL == sample) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: sample is NULL \n  \n ", LOG_LOCATION);
        return false;
    }
    
    int i=0;
    ItrServerDetails  serIter;
    lineDetails ld;
    g_cSystemLogger.LogMessage("(%s:%s:%d)::cancelid %d \n ", LOG_LOCATION,sample->ip_info[i].CancelOrderId);
    if(sample->ip_info[i].CancelOrderId!=0)
    {
    char buf[50]={0};
    char recvbuf[512]={0};
    int recvLen;
    g_cSystemLogger.LogMessage("(%s:%s:%d):: size of order vector %d \n ",LOG_LOCATION,conn->orderIds.size());
    for(i=0;i<conn->orderIds.size();i++)
    {
   
	//g_cSystemLogger.LogMessage("(%s:%s(:%d)::Inside CancelOrder %d \n", LOG_LOCATION,sample->ip_info[i].CancelOrderId);
        int pos;
        int j;
	pos+=sprintf(buf+5,"%s%d%s","#",conn->orderIds[i],"#");
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::order length %d buf %s \n", LOG_LOCATION,pos,buf);
        char c='0';
        for(j=0;j<=3;j++)
        {
        buf[j]=c;
	//g_cSystemLogger.LogMessage("(%s:%s(:%d)::Inside CancelOrder buf %c \n", LOG_LOCATION,buf[j]);
        }
	char p=(char)(((int)'0')+pos);
        buf[j]=p;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::Inside CancelOrder buf %s socketId %d \n", LOG_LOCATION,buf,CControllerThread::getInstance()->socketId);
        if(recvLen==write(CControllerThread::getInstance()->socketId,buf,sizeof(buf)))
        {
	   g_cSystemLogger.LogMessage("(%s:%s(:%d)::writeLen %d \n", LOG_LOCATION,recvLen);
           //CControllerThread::getInstance()->makeSocketConnection();
        }
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::write sucessfull writeLen %d \n", LOG_LOCATION,recvLen);

	if(recvLen=recv(CControllerThread::getInstance()->socketId,recvbuf,sizeof(recvbuf),0)<0)
        {
	 g_cSystemLogger.LogMessage("(%s:%s(:%d)::Recv Error \n", LOG_LOCATION);
	}
	g_cSystemLogger.LogMessage("(%s:%s(:%d)::RecvLen %d recvbuf %s \n", LOG_LOCATION,recvLen,recvbuf);
        strncpy(ld.CancelOrderStatus,recvbuf,sizeof(recvbuf)); 
	CcopyStructure::copyCommandData(ld, ld.line_count);
	memset(buf,0,sizeof(buf));
        pos=0;
	sleep(1);
    }
    return true;

   }

else
{
    for(i=0;i<sample->ip_info.length();i++)
{ 
    if(strcmp(sample->ip_info[i].ipadress,"")==0)
 	break;
    LIBSSH2_CHANNEL *channel2;
    LIBSSH2_SESSION *session;
    char* userName;
    char* passWord;
    struct sockaddr_in sin;
    int rc, sock, auth_pw = 0;
    char *exitsignal = (char *) "none";
    size_t lnReturnCode;
    char command[12324] = {0};
    char processes[8024] = {0};

    char *lpUserAuthList;
    g_cSystemLogger.LogMessage("(%s:%s:%d):: Debug", LOG_LOCATION);
    rc = libssh2_init(0);
    
    strcpy(ld.ipadress,sample->ip_info[i].ipadress);
    g_cSystemLogger.LogMessage("(%s:%s:%d)::Sequence Length %d ipadress %s,and psl %s  cancelOrderId %d value of i %d \n", LOG_LOCATION, sample->ip_info._length,sample->ip_info[i].ipadress,sample->ip_info[i].psl,sample->ip_info[i].CancelOrderId,i);
    sock = socket(AF_INET, SOCK_STREAM, 0);

    sin.sin_family = AF_INET;
    sin.sin_port = htons(22);
    sin.sin_addr.s_addr = inet_addr(sample->ip_info[i].ipadress);
    if (connect(sock, (struct sockaddr*) (&sin),
            sizeof (struct sockaddr_in)) != 0) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::failure establishing ssh", LOG_LOCATION);
        return -1;
    }

    session = libssh2_session_init();
    if (libssh2_session_handshake(session, sock)) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d):: failure ssh session initiation", LOG_LOCATION);


    }
   /* if((strcmp(sample->ip_info[i].ipadress,"192.168.30.32")==0)|| (strcmp(sample->ip_info[i].psl,"192.168.30.231")==0))
    {
        userName = "******";
        passWord = "******"; 
    }
    else*/
    
         userName = "******";
         passWord = "******"; 
    
    lpUserAuthList = libssh2_userauth_list(session, userName, strlen(userName));

    if (NULL == lpUserAuthList) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d):: get user auth list failed", LOG_LOCATION);

    }
    char lcPreferredAuthMethod[20] = "password";
    g_cSystemLogger.LogMessage("(%s:%s(:%d)::authentication methods(%s)", LOG_LOCATION, lpUserAuthList);
    if (strstr(lpUserAuthList, lcPreferredAuthMethod) != NULL) {
        auth_pw |= 1;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)::authentication methods(%d)", LOG_LOCATION, auth_pw);
    }
    if (auth_pw & 1) {
        if (libssh2_userauth_password(session, userName, passWord)) {
            g_cSystemLogger.LogMessage("(%s:%s(:%d)::Authentation by password failed\n", LOG_LOCATION);
        }

        else {
            g_cSystemLogger.LogMessage("(%s:%s(:%d)::Authentation by mint succesded\n", LOG_LOCATION);
        }

    }

    while ((channel2 = libssh2_channel_open_session(session)) == NULL &&
            libssh2_session_last_error(session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN) {
        waitsocket(sock, session);
    }

    if (channel2 == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail", LOG_LOCATION);
    }
   
    if(strcmp(sample->ip_info[i].psl,"Process")==0)
    {
       
    g_cSystemLogger.LogMessage("(%s:%s(:%d)) Inside Process", LOG_LOCATION);
    for(serIter=conn->getServerInfo().begin();serIter!=conn->getServerInfo().end();serIter++)
    {  
        g_cSystemLogger.LogMessage("(%s:%s(:%d)) ipadress from iter %s", LOG_LOCATION,serIter->ipAdress);
        tagServerInfo &tagServ = *serIter;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)) ipadress from tagserver %s sampeip %s \n", LOG_LOCATION,tagServ.ipAdress,sample->ip_info[i].ipadress);

        if(strcmp(tagServ.ipAdress,sample->ip_info[i].ipadress)==0)
        {
            int pos=0;
            g_cSystemLogger.LogMessage("(%s:%s(:%d)) tagServ %s sample %s processLen %d \n", LOG_LOCATION,tagServ.ipAdress,sample->ip_info[i].ipadress,tagServ.noOfProcess);
            for(int j=1;j<tagServ.noOfProcess;j++)
            {
            g_cSystemLogger.LogMessage("(%s:%s(:%d)) Process %s \n", LOG_LOCATION,tagServ.processes[j].name);
            if(j==(tagServ.noOfProcess-1))
            {
            sprintf(processes+pos,tagServ.processes[j].name);
            }
            else
            {
            pos+=sprintf(processes+pos,"%s%s",tagServ.processes[j].name,"|");
          
            }
            }
            sprintf(command,"%s %s%s%s%s %s%s%s%s","ps -ef | egrep -v ","\"", "egrep|vi|tail|cat|emacs|more|nohup","\"" ,"| egrep","\"",processes,"\"","| grep -v daemon");
            g_cSystemLogger.LogMessage("(%s:%s(:%d)) command %s", LOG_LOCATION,command);
            
            while ((rc = libssh2_channel_exec(channel2, command)) == LIBSSH2_ERROR_EAGAIN) {
            waitsocket(sock, session);
            
            
        }
           lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));
           g_cSystemLogger.LogMessage("(%s:%s(:%d)) lnReturnCode %d command %s", LOG_LOCATION,lnReturnCode,command);
           strncpy(ld.processInfo,command,sizeof(command));
            memset(command, 0, sizeof (command));
            libssh2_channel_free(channel2);
            channel2 = NULL; 
        }     
    }
    }
    
    else if((strcmp(sample->ip_info[i].psl,"Space"))==0)
    {
       while ((rc = libssh2_channel_exec(channel2, "df -kh |grep -v grep")) == LIBSSH2_ERROR_EAGAIN) {
            waitsocket(sock, session);
            
        }
        lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));
        g_cSystemLogger.LogMessage("(%s:%s(:%d)lnReturnCode %d command after executing %s\n", LOG_LOCATION, lnReturnCode, command);
        strcpy(ld.spaceInfo,command);
        memset(command, 0, sizeof (command));
        libssh2_channel_free(channel2);
        channel2 = NULL;
    }
    
    else if((strcmp(sample->ip_info[i].psl,"Line"))==0)
    {
        
        DBConnection lDBConnectionObject;
        char* dbUserName = "******";
        char* dbPassWord = "******";
        char* dbName = "mani";
        char* dbPort = "5432";
        if(0==lDBConnectionObject.getFoPiQueryResult(dbUserName,dbPassWord,dbName,dbPort,sample->ip_info[i].ipadress,ld))
        {
            g_cSystemLogger.LogMessage("(%s:%s(:%d) Failed DB query \n", LOG_LOCATION);
        }
        
        g_cSystemLogger.LogMessage("(%s:%s(:%d) LineId %d Product details %s line count %d\n", LOG_LOCATION,ld.ld[0].fo_id,ld.ld[0].product_details,ld.line_count);
        lDBConnectionObject.Close();
    }
    
    
    iterMap = conn->getPath().find(sample->ip_info[i].ipadress);
    g_cSystemLogger.LogMessage("(%s:%s(:%d))Path %s \n", LOG_LOCATION,iterMap->second.c_str());

    if (sample->ip_info[i].status == true) 
    {

        sprintf(command, "%s%s",iterMap->second.c_str(),"/clear_server.sh >> /tmp/LOGS/cronlog 2>&1 &");

        while ((rc = libssh2_channel_exec(channel2, command)) == LIBSSH2_ERROR_EAGAIN) {
            waitsocket(sock, session);
        }
        lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));
        g_cSystemLogger.LogMessage("(%s:%s(:%d)lnReturnCode %d command after executing %s\n", LOG_LOCATION, lnReturnCode, command);
        memset(command, 0, sizeof (command));
        libssh2_channel_free(channel2);
        channel2 = NULL;
    }
        
    else if((sample->ip_info[i].status==false) && ((strcmp(sample->ip_info[i].psl,""))==0) && (sample->ip_info[i].CancelOrderId==0))
    {
        sprintf(command, "%s", "cd /home/mint/ga/bin; nohup ./shutdownall.sh >> /tmp/LOGS/cronlog1 2>&1 &");

        g_cSystemLogger.LogMessage("(%s:%s(:%d)%s\n", LOG_LOCATION, command);
        while ((rc = libssh2_channel_exec(channel2, command)) == LIBSSH2_ERROR_EAGAIN) {
            g_cSystemLogger.LogMessage("(%s:%s(:%d) ERROR Running command %d\n", LOG_LOCATION, rc);
            waitsocket(sock, session);
        }

        size_t lnReturnCode;
        lnReturnCode = libssh2_channel_read(channel2, command, sizeof (command));

        g_cSystemLogger.LogMessage("(%s:%s(:%d)lnReturnCode %d commandBuffer %s\n", LOG_LOCATION, lnReturnCode, command);
        memset(command, 0, sizeof (command));
        libssh2_channel_free(channel2);
        channel2 = NULL;
    }
    g_cSystemLogger.LogMessage("(%s:%s(:%d)space %s\n", LOG_LOCATION,ld.spaceInfo);
     CcopyStructure::copyCommandData(ld, ld.line_count);
    }
}
   
       
    return true;
}
void* StartLineProcessConnector::data_recv(void* arg) {

    CControllerThread *singleInstance;
    singleInstance = CControllerThread::getInstance();
    
    StartLineProcessCollector *coll = (StartLineProcessCollector *) arg;
    StartLineProcessConnector *conn = NULL;
    g_cSystemLogger.LogMessage("(%s:%s(:%d))::Ipadress data_recv \n", LOG_LOCATION);
    if ((NULL == coll) || (NULL == (conn = coll->getConnector()))) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d))::coll is null \n", LOG_LOCATION);
        //fprintf(fp_rtc, "OR invalid RTCConnector reference received in RTCCollector object...\n");
        return NULL;
    }

    DDS_ReturnCode_t retcode_cache;
    if (NULL == conn->m_reader_cache) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d))::m_reader_cache is NULL \n", LOG_LOCATION);
        return NULL;
    }

    MONITORING::leaseProcessStartDataReader *rtc_reader = MONITORING::leaseProcessStartDataReader::narrow(conn->m_reader_cache);
    if (rtc_reader == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d))::rtc_reader is NULL \n", LOG_LOCATION);
        return NULL;
    }
    // set the enabled status = DATA_AVAILABLE
    DDSStatusCondition* status_condition = conn->m_reader_cache->get_statuscondition();
    status_condition->set_enabled_statuses(DDS_DATA_AVAILABLE_STATUS);
    // attach the status condition to the waitset
    DDSWaitSet* waitset = new DDSWaitSet();
    retcode_cache = waitset->attach_condition(status_condition);
    if (retcode_cache != DDS_RETCODE_OK) {
        g_cSystemLogger.LogMessage("(%s:%s(:%d))::retcode_cache DDS_RETCODE_OK \n", LOG_LOCATION);
        delete waitset;
        return NULL;
    }

    DDSConditionSeq activeconditions;
    DDS_Duration_t timeout = {1, 0};
    MONITORING::leaseProcessStartSeq data_seq;
    DDS_SampleInfoSeq info_seq;
    MONITORING::leaseProcessStart* sample = NULL;
    int timeout_count = 0;
    const static int MAX_TIMEOUT_COUNT = 60;

    int i = 0;
    while (1) {

        g_cSystemLogger.LogMessage("(%s:%s(:%d))::Inside While \n", LOG_LOCATION);

	if(!(singleInstance->is_connected(singleInstance->socketId)))
                singleInstance->makeSocketConnection();
	
        retcode_cache = waitset->wait(activeconditions, timeout);
        // waitset returned.. check if status changed, or if waitset timed out
        if (retcode_cache == DDS_RETCODE_TIMEOUT) {
            if (++timeout_count > MAX_TIMEOUT_COUNT) //Restrict output till 1 minute!
            {
                g_cSystemLogger.LogMessage("(%s:%s(:%d)):: timed out after <%d> seconds\n", LOG_LOCATION, MAX_TIMEOUT_COUNT);

                timeout_count = 0;
                continue;
            }

        }
        else if (retcode_cache != DDS_RETCODE_OK) {
            timeout_count = 0;
            g_cSystemLogger.LogMessage("(%s:%s(:%d)):: DDS_RETCODE_OK NOT \n", LOG_LOCATION, MAX_TIMEOUT_COUNT);
            continue;
        }
        timeout_count = 0;
        g_cSystemLogger.LogMessage("(%s:%s(:%d)):: Before Take \n", LOG_LOCATION);


        retcode_cache = rtc_reader->take(data_seq, info_seq, DDS_LENGTH_UNLIMITED,
                DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);

        if (retcode_cache == DDS_RETCODE_NO_DATA) {
            g_cSystemLogger.LogMessage("(%s:%s(:%d))::No data Found\n", LOG_LOCATION);

        }
        else if (retcode_cache != DDS_RETCODE_OK) {
            g_cSystemLogger.LogMessage("(%s:%s(:%d))::DDS_RETCODE_OK NOT\n", LOG_LOCATION);

        }
        g_cSystemLogger.LogMessage("(%s:%s(:%d))::Data_seq Length %d\n", LOG_LOCATION, data_seq.length());
        for (i = 0; i < data_seq.length(); ++i) {
            if (info_seq[i].valid_data) {

                sample = &data_seq[i];

                //Invoke collector's action here!
                if (false == coll->collect(sample, conn)) {

                    if (DDS_RETCODE_OK != rtc_reader->return_loan(data_seq, info_seq)) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))::Error ---> RTCConnector::rtc_data_receiving() return loan error\n", LOG_LOCATION);

                    }
                    goto endgame;
                }
            } // if (info_seq[i].valid_data)...
        }//for..data_seq.length()..

        retcode_cache = rtc_reader->return_loan(data_seq, info_seq);
        if (retcode_cache != DDS_RETCODE_OK) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Error ---> RTCConnector::rtc_data_receiving()  loan error\n", LOG_LOCATION);

        }
    } //while...

    /* Delete all entities - to cleanup properly! */
endgame:
    waitset->detach_condition(status_condition);
    delete waitset;
    return NULL;
}
RET_CODE serverConnectThread::Process(void* pcThreadParam) {

    CControllerThread *singleInstance;
    singleInstance = CControllerThread::getInstance();
    
    iterServerInfoMap iterMap;
    typedef tbb::concurrent_vector<tapServerInfoMap> mapStore;
    typedef mapStore::iterator iterMapVector;
    mapStore mapStoreObj;
    int whileserverCount = 0;
    
   // CControllerThread *singleInstance;
   // singleInstance = CControllerThread::getInstance();

    unsigned long long int prevSizeroot = 0;
    unsigned long long int currentSizeroot = 0;
    unsigned long long int prevSizedolat = 0;
    unsigned long long int currentSizedolat = 0;
    vector <unsigned long long int> fileSize;
    for(int i=0;i<10;i++)
	fileSize.push_back(0);
   	
    char *hostAdress;
    const char* userName;
    const char* passWord;
    char* dbUserName;
    char* dbPassWord;
    char* dbName;
    char* dbPort;
    char* lineType;
    int globalCounter = 0;
    int count = 0;
    bool breakFlag;
    char commandBuffer[1000];
    char buffer[50];
    char c[20];
    int lProcessListIndex, lSpaceList;
    FILE *p;
   // char *lcPreferredAuthMethod[20];
    int lineCounter;
    DBConnection lDBConnectionObject;
    
    while (1) {
        count = 0;
        breakFlag = false;
        //print_micro_sec(1,stdout);
        for (int i=0;i<(singleInstance->serverObject.size()/3);i++) {
            
            lineCounter =0;
            if (IsThreadInShutdown()) {

                breakFlag = true;
                break;
            }
            tapServerInfoMap m_MapObject;
            tagServerInfo &tsi = singleInstance->serverObject[i];
            
	    //if(tsi.bIsDirty == false)
		//tsi.bIsDirty = true;
            //else
                //continue;            
            hostAdress = tsi.ipAdress;
	    cout <<"hostAdress1 ::: " << tsi.ipAdress << endl;
            userName = tsi.userName;
            passWord = tsi.password;
            dbUserName = tsi.dbUserName;
            dbPassWord = tsi.dbPassword;
            dbName = tsi.dbName;
            dbPort = tsi.dbPort;
            
            //cout <<"FilePath---" << tsi.Path[0].filePath << endl;
    //FILE *fp = fopen("LineIds.txt","w+");
            //lineType = tsi.lineType;

            globalCounter = 0;
            if (!(tsi.dbconStatus)) {
                
                if (0 == lDBConnectionObject.getQueryResult(m_MapObject, dbUserName, dbPassWord, dbName, dbPort, hostAdress, lineType)) {
                   // printf("db connection not found \n");

	          /*  for (std::map <long,std::string>::iterator iterMap = m_MapObject.begin(); iterMap != m_MapObject.end(); iterMap++)
                        {
                        fprintf(fp,"\n");
                        fprintf(fp,"%ld",(*iterMap).first);
                        }*/
                }
		for (std::map <long,std::string>::iterator iterMap = m_MapObject.begin(); iterMap != m_MapObject.end(); iterMap++)
		{		      
	 	  //cout << "userIds::" << iterMap->second << endl;
		  //cout << "first::" << iterMap->first << endl;
 		  conn->orderIds.push_back(iterMap->first);	
                }
                //std::cout<<"m_MapObject"<<m_MapObject.size()<<endl;
                mapStoreObj.push_back(m_MapObject);
                lDBConnectionObject.Close();
                tsi.dbconStatus = true;

            }
	    //memset(buffer,'\0',sizeof(buffer));
            //commandBuffer[1000] = {0};
           // buffer[50] = {0};
           // c[20] = {0};
           
            char *lpUserAuthList;
            struct sockaddr_in sin;
            int rc, sock, auth_pw = 0;
            lProcessListIndex, lSpaceList = 1;

            sprintf(buffer, "ping -c 3 %s | grep -c %s", tsi.ipAdress, "\"3 received\"");
	    g_cSystemLogger.LogMessage("(%s:%s:%d)::Ping Buffer %s", LOG_LOCATION,buffer);
            p = popen(buffer, "r");
            fgets(c, 10, p);
	    //cout << "ping Commmand buff" << buffer << endl;
	   // cout <<" C " << c << endl;
            //pclose(p);
            g_cSystemLogger.LogMessage("(%s:%s:%d)::If Ping Output %s", LOG_LOCATION,c);

            if (atoi(c) == 1) {
                tsi.serverstatus = true;
            } else {
		usleep(1000);
		p = popen(buffer,"r");
		fgets(c,10,p);
		pclose(p);
                g_cSystemLogger.LogMessage("(%s:%s:%d)::Else Ping Output %s", LOG_LOCATION,c);
		cout << "Else C" << c << endl;
		if(atoi(c) == 1)
		{
			tsi.serverstatus = true;
		}
		else
		{
			tsi.serverstatus = false;
			CcopyStructure::copyData(tsi,0,0,0);
			continue;
		}
               
            }
            
	    memset(buffer,'\0',sizeof(buffer));
            memset(c,'\0',sizeof(c));
            rc = libssh2_init(0);

            if (rc != 0) {
                g_cSystemLogger.LogMessage("(%s:%s:%d)::failure establishing ssh", LOG_LOCATION);
                return 1;
            }

            if (tsi.serverstatus == true && tsi.conectstatus == false) {

                sock = socket(AF_INET, SOCK_STREAM, 0);
                tsi.m_socketId = sock;
                sin.sin_family = AF_INET;
                sin.sin_port = htons(22);
                sin.sin_addr.s_addr = inet_addr(tsi.ipAdress);
                if (connect(sock, (struct sockaddr*) (&sin),
                        sizeof (struct sockaddr_in)) != 0) {
                    g_cSystemLogger.LogMessage("(%s:%s(:%d)::failure establishing ssh", LOG_LOCATION);
                    return -1;
                }
                session = libssh2_session_init();
                if (libssh2_session_handshake(session, tsi.m_socketId)) {
                    return -1;
                }
                tsi.session = session;

                lpUserAuthList = libssh2_userauth_list(session, userName, strlen(userName));

                if (NULL == lpUserAuthList) {
                    g_cSystemLogger.LogMessage("(%s:%s(:%d):: get user auth list failed", LOG_LOCATION);
                    continue;
                }

               char lcPreferredAuthMethod[20] = "password";

                g_cSystemLogger.LogMessage("(%s:%s(:%d)::authentication methods(%s)", LOG_LOCATION, lpUserAuthList);
                if (strstr(lpUserAuthList, lcPreferredAuthMethod) != NULL) {
                    auth_pw |= 1;
                    g_cSystemLogger.LogMessage("(%s:%s(:%d)::authentication methods(%d)", LOG_LOCATION, auth_pw);
                }
                g_cSystemLogger.LogMessage("(%s:%s(:%d)::after auth_pw methods(%d)", LOG_LOCATION, auth_pw);
                if (auth_pw & 1) {

                    if (libssh2_userauth_password(session, userName, passWord)) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d)::Authentation by password failed\n", LOG_LOCATION);

                    } else {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d)::Authentation by password succeded\n", LOG_LOCATION);
                    }
                }
                tsi.session = session;
                tsi.conectstatus = true;
            }

            tapServerInfoMap &MapObject = mapStoreObj.at(count++);

            if (strcmp(tsi.lineType, "FO") == 0) {
                
                int i=0;
                for (iterMap = MapObject.begin(); iterMap != MapObject.end(); iterMap++) {
                  
                     while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }
                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }
                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", iterMap->second.c_str(), ":", 9602, ".*", "ESTABLISHED", "\"");

                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    int lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));
                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::commandBuffer %s lnreturncode %d\n", LOG_LOCATION,commandBuffer,lnReturnCode);
                    
                    //std::cout<<"iterMap->first" <<iterMap->first <<endl;
                    if (commandBuffer[0] == '1') {
                        
                        strncpy(tsi.lineInfo[i].ipv4adresss, iterMap->second.c_str(), 16);
                        tsi.lineInfo[i].ipv4adresss[16] = '\0';
                        
                        tsi.lineInfo[i].status = TRUE;
                        tsi.lineInfo[i].userId = iterMap->first;
                    } 
                    else if (commandBuffer[0] == '0') {
                        
                        strncpy(tsi.lineInfo[i].ipv4adresss, iterMap->second.c_str(), 16);
                        tsi.lineInfo[i].ipv4adresss[16] = '\0';
                        
                        tsi.lineInfo[i].status = FALSE;
                        tsi.lineInfo[i].userId = iterMap->first;
                    }
                    //std::cout<<"tsi.lineInfo[lineCounter].userId" <<tsi.lineInfo[lineCounter].userId <<endl;
                    //std::cout<<"tsi.lineInfo[lineCounter].status" <<tsi.lineInfo[lineCounter].status <<endl;
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    i++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                }
                //globalCounter = lineCounter;

            }

           /* if (strcmp(tsi.lineType, "CM") == 0) {

                int lineCounter = 0;
                for (iterMap = MapObject.begin(); iterMap != MapObject.end(); iterMap++) {
                    while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", iterMap->second.c_str(), ":", 9601, ".*", "ESTABLISHED", "\"");

                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    int lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                    if (commandBuffer[0] == '1') {
                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, iterMap->second.c_str(), 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                        
                        tsi.lineInfo[lineCounter].status = TRUE;
                        tsi.lineInfo[lineCounter].userId = iterMap->first;
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, iterMap->second.c_str(), 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                        
                        tsi.lineInfo[lineCounter].status = FALSE;
                        tsi.lineInfo[lineCounter].userId = iterMap->first;
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);elOrderI
                    channel = NULL;
                }
                globalCounter = lineCounter;

            }
		
 */
	  // for(int i=1;i<tsi.noOfFilePath;i++)
           // {
              //  printf("Inside Filesizecheck \n");
	   // cout <<"filePath::::" << tsi.Path[0].filePath << endl;
            if (!(strcmp(tsi.Path[0].filePath,"") == 0))
            {
                while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }               
                    sprintf(commandBuffer,"%s %s %s", "du -b",tsi.Path[0].filePath,"| awk '{print $1}' ");
                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    size_t lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));
                    
                    char buff[30];                    
                    int j=0;
		    int i=0; 		    
                    while(commandBuffer[j]!='\n')
                    {
                        buff[i]=commandBuffer[j];
                        j++;
			i++;
			lnReturnCode--;			
                    }
	            
		    lnReturnCode--;
                    currentSizeroot = (atoi(buff));		   
		    if(lnReturnCode)
		    {		   
		    i=0;
		    j++;		    		    
		    memset(buff,0,sizeof(buff));		   		   
		    while(commandBuffer[j]!='\n')
                    {
                        buff[i]=commandBuffer[j];
                        j++;
			i++;
			lnReturnCode--;
                    }
		    }
		    currentSizedolat = (atoi(buff));
                    
	    	    //cout <<"currentSizeroot" << currentSizeroot <<" "<<fileSize[0] <<endl;
		    //cout <<"currentSizedolat" << currentSizedolat <<" " <<fileSize[1] <<endl;
		    
		    if(currentSizeroot!=currentSizedolat)
	            {
			if((currentSizeroot-fileSize[0])>0 && (currentSizedolat-fileSize[1])>0)
                    	{
                        	tsi.Path[0].status=true;
                    	}
		    
                    	else
                    	{
                        	tsi.Path[0].status=false;
                    	}
			fileSize.insert(fileSize.begin()+0,currentSizeroot);
                        fileSize.insert(fileSize.begin()+1,currentSizedolat);

		    }		                        
                    
                    else
                    {
                        if((currentSizeroot-fileSize[2])>0)
                        {
                                tsi.Path[0].status=true;
                        }
                    
                        else
                        {
                                tsi.Path[0].status=false;
                        }
			fileSize.insert(fileSize.begin()+2,currentSizeroot);
                    }
                    
          		                                          
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
           // }
            }
	
	   /* std::cout<<"tsi.lineType"<<tsi.lineType<<endl;
            if (strcmp(tsi.lineType, "ColoBridge") == 0) {
	singleInstance	 g_cSystemLogger.LogMessage("(%s:%s(:%d))::Inside ColoBridge \n", LOG_LOCATION);

		memset(tsi.lineType, 0, sizeof (tsi.lineType));
		strcpy(tsi.lineType,"CM");
		std::cout<<"LineType"<<tsi.lineType<<endl;
                int lineCounter = 0;
               
                    while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", "192.168.30.32", ":", 2004, ".*", "ESTABLISHED", "\"");

                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    int lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                    if (commandBuffer[0] == '1') { tsi.lineInfo[lineCounter].userId=2004;

                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.32", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                        tsi.lineInfo[lineCounter].userId=2004;
                        tsi.lineInfo[lineCounter].status = TRUE;
                        
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.32", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=2004;
                        tsi.lineInfo[lineCounter].status = FALSE;
                        
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                    
                     while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", "192.168.30.32", ":", 2005, ".*", "ESTABLISHED", "\"");

                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                    if (commandBuffer[0] == '1') {
                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.32", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=2005;
                        tsi.lineInfo[lineCounter].status = TRUE;
                        
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.32", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                        tsi.lineInfo[lineCounter].userId=2005;
                        tsi.lineInfo[lineCounter].status = FALSE;
                        
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                    singleInstance->serverObject.size()
                       while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", "192.168.30.32", ":", 5432, ".*", "ESTABLISHED", "\"");

                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                    if (commandBuffer[0] == '2') {
                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.32", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                        tsi.lineInfo[lineCounter].userId=5432;
                        tsi.lineInfo[lineCounter].status = TRUE;
                        
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.32", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=5432;
                        tsi.lineInfo[lineCounter].status = FALSE;
                        
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                    
                    while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", "192.168.30.231", ":", 2004, ".*", "ESTABLISHED", "\"");
singleInstance->serverObject.size()
                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                    lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                    if (commandBuffer[0] == '1') {
                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.231", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=2004;
                        tsi.lineInfo[lineCounter].status = TRUE;
                        
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.231", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=2004;
                        tsi.lineInfo[lineCounter].status = FALSE;
                        
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                    
                    while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", "192.168.30.231", ":", 2005, ".*", "ESTABLISHED", "\"");

                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                     lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                    if (commandBuffer[0] == '1') {
                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.231", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=2005;
                        tsi.lineInfo[lineCounter].status = TRUE;
                        
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.231", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=2005;
                        tsi.lineInfo[lineCounter].status = FALSE;
                        
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                    
                     while (((channel = libssh2_channel_open_session(tsi.session)) == NULL) &&
                            (libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN)) {

                        waitsocket(sock, tsi.session);
                    }

                    if (channel == NULL) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))ssh channel opening fail",LOG_LOCATION);
                        // goto shutdown;
                    }

                    sprintf(commandBuffer, "%s  %s%s%s%d%s%s%s", "/bin/netstat -n|/bin/grep -c", "\"", "192.168.30.231", ":", 5432, ".*", "ESTABLISHED", "\"");

                    g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for netstat %s\n", LOG_LOCATION, commandBuffer);
                    while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                        waitsocket(sock, tsi.session);
                    }
                     lnReturnCode;
                    lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));
		    //std::cout<<"lnReturnCode"<<lnReturnCode<<endl;
                    if (commandBuffer[0] == '2') {
                       
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.231", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=5432;
                        tsi.lineInfo[lineCounter].status = TRUE;
                        
                    }  else if (commandBuffer[0] == '0') {
               
                        strncpy(tsi.lineInfo[lineCounter].ipv4adresss, "192.168.30.231", 16);
                        tsi.lineInfo[lineCounter].ipv4adresss[16] = '\0';
                         tsi.lineInfo[lineCounter].userId=5432;
                        tsi.lineInfo[lineCounter].status = FALSE;
                        
                    }
                    if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                        waitsocket(sock, tsi.session);
                    }
                    lineCounter++;
                    memset(commandBuffer, 0, sizeof (commandBuffer));
                    libssh2_channel_free(channel);
                    channel = NULL;
                
                globalCounter = lineCounter;

            }*/
               
            for (lProcessListIndex = 1; lProcessListIndex < tsi.noOfProcess; lProcessListIndex++) {
                g_cSystemLogger.LogMessage("(%s:%s(:%d))::process name\n", LOG_LOCATION);
                while ((channel = libssh2_channel_open_session(tsi.session)) == NULL &&
                        libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN) {
                    waitsocket(sock, tsi.session);
                }
                if (channel == NULL) {
                    fprintf(stderr, "failure establishing ssh");
                    //goto shutdown;
                }
                sprintf(commandBuffer, "%s %s", "pidof -s", tsi.processes[lProcessListIndex].name);
                g_cSystemLogger.LogMessage("(%s:%s(:%d)):: Pid of process command %s\n", LOG_LOCATION, commandBuffer);

                while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                    waitsocket(sock, tsi.session);
                    
                }
                size_t lnReturnCode;
                lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));
                g_cSystemLogger.LogMessage("(%s:%s(:%d))::commandBuffer %s lnreturncode %d\n", LOG_LOCATION,commandBuffer,lnReturnCode);
                if (lnReturnCode == 0) {
                    tsi.processes[lProcessListIndex].process_on_off = FALSE;

                } else {
                    tsi.processes[lProcessListIndex].process_on_off = TRUE;

                    if (lnReturnCode != LIBSSH2_ERROR_EAGAIN) {
                        g_cSystemLogger.LogMessage("(%s:%s(:%d))::libbssh2 %d\n", LOG_LOCATION, lnReturnCode);
                    }
                }
                if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                    waitsocket(sock, tsi.session);
                }
                g_cSystemLogger.LogMessage("(%s:%s(:%d))::tsi.processes[i].process_on_off %d \n", LOG_LOCATION, tsi.processes[lProcessListIndex].process_on_off);
                memset(commandBuffer, 0, sizeof (commandBuffer));
                if (channel) {
                    libssh2_channel_free(channel);
                    channel = NULL;
                }
            }
            char percnt[5] = "\"%\"";
            for (lSpaceList = 1; lSpaceList < tsi.noOfSpace; lSpaceList++) {

                while ((channel = libssh2_channel_open_session(tsi.session)) == NULL &&
                        libssh2_session_last_error(tsi.session, NULL, NULL, 0) == LIBSSH2_ERROR_EAGAIN) {
                    waitsocket(sock, tsi.session);
                }

                if (channel == NULL) {
                    g_cSystemLogger.LogMessage("failure establishing ssh");
                }
                sprintf(commandBuffer, "%s %s  %s %s %s", "df -hk | grep", tsi.space[lSpaceList].name, "| awk '{print $(NF-1)}' | awk -F", percnt, "'{print $1}'");
                g_cSystemLogger.LogMessage("(%s:%s(:%d))::command for space%s\n", LOG_LOCATION, commandBuffer);
                while ((rc = libssh2_channel_exec(channel, commandBuffer)) == LIBSSH2_ERROR_EAGAIN) {
                    waitsocket(sock, tsi.session);

                }
                int lnReturnCode;
                lnReturnCode = libssh2_channel_read(channel, commandBuffer, sizeof (commandBuffer));

                if (lnReturnCode >= 0) {
                    if (atoi(commandBuffer) > 90) {
                        tsi.space[lSpaceList].space_full = TRUE;
                    } else {
                        tsi.space[lSpaceList].space_full = FALSE;
                    }
                }


                if (LIBSSH2_ERROR_EAGAIN == lnReturnCode) {
                    waitsocket(sock, tsi.session);
                }
                memset(commandBuffer, 0, sizeof (commandBuffer));
                if (channel) {
                    libssh2_channel_free(channel);
                    channel = NULL;
                }
            }
            CcopyStructure::copyData(tsi, tsi.noOfProcess, tsi.noOfSpace, tsi.noOfLine);

        }
       // whileserverCount++;
        //std::cout << "while count" << whileserverCount << endl;
        ///if(!(singleInstance->is_connected(singleInstance->socketId)))
		//singleInstance->makeSocketConnection();
	
        if (breakFlag) {
            break;
        }
    }
     for (int i=0;i<(singleInstance->serverObject.size()/3);i++) {
        tagServerInfo tsi;
        tsi = (singleInstance->serverObject[i]);

        libssh2_session_disconnect(tsi.session, "Shutting down,thank you");
        libssh2_session_free(tsi.session);
        close(tsi.m_socketId);
        libssh2_exit();
    }
    return 1;
}