/[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.1 by sysadm, Fri Jul 2 11:22:07 2004 UTC Revision 1.8 by sysadm, Tue Aug 10 19:54:16 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 21  Line 21 
21  using namespace std;  using namespace std;
22    
23  base::base(void)  base::base(void)
24  : innd_uid(0)  : p_ParentThread(NULL)
25    , p_ThreadPool(NULL)
26    , ulMainThreadId(0)
27    , innd_uid(0)
28  , isConnected(false)  , isConnected(false)
29  , running(false)  , running(false)
30  {  {
# Line 29  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 271  int base::bbs_post(const CString& head, Line 276  int base::bbs_post(const CString& head,
276                                                  this->Db.ExecuteSQL(sql);                                                  this->Db.ExecuteSQL(sql);
277                                                  rid = this->last_insert_id();                                                  rid = this->last_insert_id();
278    
279                                                  //Send notification message                                                  //Send notication message
280    
281                          msg_content.Format("[hi]SYS_R_Reply_Article[/hide]"                            msg_content.Format("[hide]SYS_R_Reply_Article[/hide]"
282                                                          "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld"                                                          "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld"
283                                                          "]看看[/url]《%s》吧!\n",rid,addslashes(subject));                                                          "]看看[/url]《%s》吧!\n",rid,addslashes(subject));
284    
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,content,send_dt,send_ip)"
287                                                                  " valulues(%ld,%ld,'%s',now(),'%s')",                                                                  " values(%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 299  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[1024];
308                    e->GetErrorMessage(strErrMsg,1024);
309                    syslog << logfile::log_head << "Error in bbs_post() [" << strErrMsg << "]" << endl;
310                  e->Delete();                  e->Delete();
311                  return -1;                  return -1;
312          }          }
# Line 384  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[1024];
402                    e->GetErrorMessage(strErrMsg,1024);
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 452  int base::s_receive(CString& out_str, co Line 461  int base::s_receive(CString& out_str, co
461          return total_read;          return total_read;
462  }  }
463    
 bool base::IsRunning(void)  
 {  
         return this->running;  
 }  
   
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 496  DWORD base::Thread(LPVOID pParam) Line 502  DWORD base::Thread(LPVOID pParam)
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;
507    
508            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;
513            }
514            p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
515    
516          p->w_call();          p->w_call();
517    
518            if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0)
519            {
520                    syslog << logfile::log_head << "Unregister thread ... Failed" << endl;
521            }
522    
523          syslog << logfile::log_head << "Thread stopped." << endl;          syslog << logfile::log_head << "Thread stopped." << endl;
524    
525          return 0;          return 0;
# Line 537  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