/[LeafOK_CVS]/innwebd/base.cpp
ViewVC logotype

Diff of /innwebd/base.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 by sysadm, Sat Jul 3 13:56:04 2004 UTC Revision 1.6 by sysadm, Sun Jul 4 22:49:03 2004 UTC
# Line 1  Line 1 
1  /*******************************************************/  /*******************************************************/
2  /*                                                     */  /*                                                     */
3  /*  LeafOK Innd                                        */  /*  LeafOK Innbbsd                                     */
4  /*  Copyright (C) LeafOK.com, 2003-2004                */  /*  Copyright (C) LeafOK.com, 2003-2004                */
5  /*                                                     */  /*                                                     */
6  /*  Programmed by Leaf                                 */  /*  Programmed by Leaf                                 */
7  /*  E-mail:leaf@leafok.com  QQ:6049044                 */  /*  E-mail:leaflet@leafok.com  QQ:6049044              */
8  /*                                                     */  /*                                                     */
9  /*  http://bbs.leafok.com                              */  /*  http://bbs.leafok.com                              */
10  /*  http://bbs.leafok.net                              */  /*  http://bbs.leafok.net                              */
# Line 22  using namespace std; Line 22  using namespace std;
22    
23  base::base(void)  base::base(void)
24  : p_ParentThread(NULL)  : p_ParentThread(NULL)
25    , p_ThreadPool(NULL)
26    , ulMainThreadId(0)
27  , innd_uid(0)  , innd_uid(0)
28  , isConnected(false)  , isConnected(false)
29  , running(false)  , running(false)
# Line 30  base::base(void) Line 32  base::base(void)
32    
33  base::~base(void)  base::~base(void)
34  {  {
35            if (this->GetThreadPool() != NULL)
36                    delete (this->GetThreadPool());
37  }  }
38    
39  int base::s_exec(const char* in_str, CString& out_str, const char* end_str)  int base::s_exec(const char* in_str, CString& out_str, const char* end_str)
# Line 281  int base::bbs_post(const CString& head, Line 285  int base::bbs_post(const CString& head,
285                                                  RS.GetFieldValue("UID",dbVar,SQL_C_SLONG);                                                  RS.GetFieldValue("UID",dbVar,SQL_C_SLONG);
286                                                  sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)"                                                  sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)"
287                                                                  " valulues(%ld,%ld,'%s',now(),'%s')",                                                                  " valulues(%ld,%ld,'%s',now(),'%s')",
288                                                                  this->innd_uid,dbVar.m_lVal,addslashes(msg_connt),ththis->hostaddr);                                                                  this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr);
289                                                  this->Db.ExecuteSQL(sql);                                                  this->Db.ExecuteSQL(sql);
290                                          }                                          }
291                                  }                                  }
292                                  RS.Close();                                  RS.Close();
293                          }                          }
294    
295                          sql.Format("insert delayed into innd_logfile(AID,art_id,msg_id,op) values"                          sql.Format("insert delayed into innd_log(AID,art_id,msg_id,op) values"
296                                  "(%ld,%ld,'%s','I')",                                  "(%ld,%ld,'%s','I')",
297                                  aid,art_id,addslashes(msg_id));                                  aid,art_id,addslashes(msg_id));
298                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
# Line 300  int base::bbs_post(const CString& head, Line 304  int base::bbs_post(const CString& head,
304          }          }
305          catch(CException* e)          catch(CException* e)
306          {          {
307                  syslog << logfile::log_head << "Error in bbs_post()" << endl;                  char strErrMsg[256];
308                    e->GetErrorMessage(strErrMsg,256);
309                    syslog << logfile::log_head << "Error in bbs_post() [" << strErrMsg << "]" << endl;
310                  e->Delete();                  e->Delete();
311                  return -1;                  return -1;
312          }          }
# Line 385  int base::bbs_delete(long id) Line 391  int base::bbs_delete(long id)
391                                  this->Db.ExecuteSQL(sql);                                  this->Db.ExecuteSQL(sql);
392                          }                          }
393    
394                          sql.Format("update innd_logfile set cancel=1 where AID=%ld",id);                          sql.Format("update innd_log set cancel=1 where AID=%ld",id);
395                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
396                  }                  }
397                  RS.Close();                  RS.Close();
398          }          }
399          catch(CException* e)          catch(CException* e)
400          {          {
401                  syslog << logfile::log_head << "Getting article error in bbs_delete()" << endl;                  char strErrMsg[256];
402                    e->GetErrorMessage(strErrMsg,256);
403                    syslog << logfile::log_head << "Getting article error in bbs_delete() [" << strErrMsg << "]" << endl;
404                  e->Delete();                  e->Delete();
405                  return -1;                  return -1;
406          }          }
# Line 455  int base::s_receive(CString& out_str, co Line 463  int base::s_receive(CString& out_str, co
463    
464  int base::begin(void)  int base::begin(void)
465  {  {
466            HANDLE hThread;
467          ULONG ulThreadId;          ULONG ulThreadId;
468          unsigned int time_wait = 0;          unsigned int time_wait = 0;
469    
470          if (!this->IsShutdown())          if (!this->IsShutdown())
471                  return 1;                  return 1;
472    
473          if (this->hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId))          if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId))
474          {          {
475                    CloseHandle(hThread);
476                  syslog << logfile::log_head << "Create thread ... OK" << endl;                  syslog << logfile::log_head << "Create thread ... OK" << endl;
477          }          }
478          else          else
# Line 489  int base::begin(void) Line 499  int base::begin(void)
499    
500  DWORD base::Thread(LPVOID pParam)  DWORD base::Thread(LPVOID pParam)
501  {  {
         HANDLE hThreadCurrent;  
502          base* p;          base* p;
503    
504          syslog << logfile::log_head << "Thread started." << endl;          syslog << logfile::log_head << "Thread started." << endl;
505    
506          p = (base*)pParam;          p = (base*)pParam;
         hThreadCurrent = GetCurrentThread();  
507    
508          if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0)          p->ulMainThreadId = GetCurrentThreadId();
509    
510            if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0)
511          {          {
512                  syslog << logfile::log_head << "Register thread ... Failed" << endl;                  syslog << logfile::log_head << "Register thread ... Failed" << endl;
513          }          }
514          p->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING);          p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
515    
516          p->w_call();          p->w_call();
517    
518          if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0)          if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0)
519          {          {
520                  syslog << logfile::log_head << "Unregister thread ... Failed" << endl;                  syslog << logfile::log_head << "Unregister thread ... Failed" << endl;
521          }          }
# Line 549  int base::Startup(void) Line 559  int base::Startup(void)
559  {  {
560          return 0;          return 0;
561  }  }
562    
563    bool base::IsThreadActive(void)
564    {
565            bool bIsActive = false;
566    
567            switch (this->GetParentThread()->GetThreadPool()->GetThreadStatus(this->ulMainThreadId))
568            {
569            case thread_pool::S_WAITING:
570            case thread_pool::S_WORKING:
571                    bIsActive = true;
572                    break;
573            default:
574                    bIsActive = false;
575            }
576    
577            return bIsActive;
578    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1