• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            socketref,再見!高德

            https://github.com/adoggie

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              246 Posts :: 4 Stories :: 312 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(54)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            #

            #ifndef _BT_THREAD_H
            #define _BT_THREAD_H

            #include <windows.h>

            class btworkThread{
            public:
            ?? ?btworkThread( void(*entry)(btworkThread* ,void*),void* user){?? ??? ?
            ?? ??? ?_entry = entry;?? ??? ?
            ?? ??? ?_param = user;
            ?? ??? ?_thandle = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)btworkThread::run,user,NULL,&_tid);
            ?? ?}
            ?? ?void?? ?stop(){
            ?? ??? ?_loop = false;
            ?? ?}
            ?? ?void?? ?wait(){
            ?? ??? ?while(!_end){
            ?? ??? ??? ?Sleep(20);
            ?? ??? ?}
            ?? ??? ?Sleep(20);? // ensure that thread has terminated
            ?? ?}
            ?? ?void?? ?stopAndWait(){
            ?? ??? ?stop();wait();
            ?? ?}
            ?? ?bool?? ?loop(){
            ?? ??? ?return _loop;
            ?? ?}
            ?? ?void?? ?code_begin(){
            ?? ??? ?_loop = true; _begin = true;_end=false;
            ?? ?}
            ?? ?void?? ?code_end(){
            ?? ??? ?_loop = false; _begin = false;_end=true;
            ?? ??? ?CloseHandle(_thandle);
            ?? ?}
            protected:
            ?? ?static void?? ?run(btworkThread* thread){
            ?? ??? ?thread->_entry(thread,thread->_param);
            ?? ?}
            private:
            ?? ?volatile bool?? ?_loop,_begin,_end;
            ?? ?void (*_entry)(btworkThread* ,void*);
            ?? ?void*?? ?_param;
            ?? ?DWORD?? ?_tid;
            ?? ?HANDLE?? ?_thandle;
            };
            posted @ 2007-02-23 22:47 放屁阿狗 閱讀(697) | 評論 (3)編輯 收藏

            ??? #include "btMutex.h"

            template <typename T>
            class SmartHandlePtr{
            ??? struct Handle{
            ??? ??? Handle(){
            ??? ??? ??? ptr = NULL;
            ??? ??? ??? cnt = 0;
            ??? ??? }
            ??? ??? void*??? ptr;
            ??? ??? int??? ??? cnt;
            ??? ??? btLock??? lock;
            ??? ??? void??? inc(){
            ??? ??? ??? btScopeLock sl(lock);
            ??? ??? ??? cnt++;
            ??? ??? }
            ??? ??? void??? dec(){
            ??? ??? ??? btScopeLock sl(lock);
            ??? ??? ??? cnt--;
            ??? ??? }
            ??? };
            public:
            ??? SmartHandlePtr(const T* p){
            ??? ??? _ph = new Handle;
            ??? ??? _ph->ptr =(void*) p;
            ??? ??? _ph->inc();
            ??? }

            ??? ~SmartHandlePtr(){
            ??? ??? if( _ph ){
            ??? ??? ??? _ph->dec();
            ??? ??? ??? if( _ph->cnt==0){
            ??? ??? ??? ??? T* p;
            ??? ??? ??? ??? p = (T*)_ph->ptr;
            ??? ??? ??? ??? if( p ){
            ??? ??? ??? ??? ??? delete p;
            ??? ??? ??? ??? }
            ??? ??? ??? ??? delete _ph;
            ??? ??? ??? }??? ??? ???
            ??? ??? }
            ??? }

            ??? SmartHandlePtr(const SmartHandlePtr& shp){
            ??? ??? if( _ph ){
            ??? ??? ??? _ph->dec();
            ??? ??? ??? if( _ph->cnt==0){
            ??? ??? ??? ??? T* p;
            ??? ??? ??? ??? p = (T*)_ph->ptr;
            ??? ??? ??? ??? if( p){
            ??? ??? ??? ??? ??? delete p;
            ??? ??? ??? ??? }
            ??? ??? ??? ??? delete _ph;
            ??? ??? ??? }??? ??? ???
            ??? ??? }
            ??? ??? _ph = _ph;
            ??? ??? _ph->inc();
            ??? }
            ??? bool operator==(const T* p) {
            ??? ??? return _ph->ptr == p;
            ??? }
            ??? bool operator==(const SmartHandlePtr& shp){
            ??? ??? return _ph == shp._ph;
            ??? }

            ??? T* operator->(){
            ??? ??? return (T*)_ph->ptr;
            ??? }

            ??? T* get(){
            ??? ??? if( _ph && _ph->ptr){
            ??? ??? ??? return (T*)_ph->ptr;
            ??? ??? }
            ??? ??? return NULL;
            ??? }

            private:
            ??? Handle*??? _ph;
            };
            posted @ 2007-02-23 22:39 放屁阿狗 閱讀(1193) | 評論 (0)編輯 收藏

            我的小狗在2006.8.21出世了,這個世界除了干活之外多了點活躍的氣息。
            小狗不好帶,但也盡量去嘗試做父親的責任
            posted @ 2006-09-03 11:22 放屁阿狗 閱讀(173) | 評論 (0)編輯 收藏

            我記得有個Omni的類庫中有對線程的封裝,看了看,不爽
            ACE也有線程類,不過要用必須連接其龐大的ace.so 不爽
            ICE也有,不過太簡單
            還是自己寫:
            哈哈,支持win32和posix接口
            這個咚咚已經在好多地方用過,希望提點

             1 
             2 #ifndef _THREAD_H
             3 #define _THREAD_H
             4 
             5 #include "nv_vartype.h"
             6 #include "nvplat.h"
             7 
             8 #ifdef WIN32
             9 #include <windows.h>
            10 typedef HANDLE NVHANDLE;
            11 
            12 #define NVCreateThead(handle,proc,param,bret) {\
            13                                                 DWORD thrid;\
            14                                                 handle = CreateThread(0,0,(LPTHREAD_START_ROUTINE)proc,(void*)param,0,&thrid);\
            15                                                 bret  = true;\
            16                                               }
            17 #define THREAD_DETACH
            18 
            19 #endif
            20 
            21 #ifdef _UNIX
            22 typedef pthread_t NVHANDLE;
            23 
            24 #define NVCreateThead(handle,proc,param,bret)    {\
            25                                                  int ret;\
            26                                                  ret= pthread_create(&handle,0,proc,param);\
            27                                                  bret= (ret!=0)?false:true;\
            28                                                 }
            29 #define THREAD_DETACH            pthread_detach(pthread_self());
            30 #endif
            31 
            32 
            33 typedef void *(*THREAD_PROC)(void *param);
            34 
            35 
            36 class NVThread{
            37 public:
            38     enum STATUS{
            39         RUNNING,
            40         STOP
            41     };
            42     enum WHERE{
            43         HEAD,
            44         TAIL
            45     };
            46     NVThread();
            47     ~NVThread();    
            48     bool        Create(void *param=0);
            49     void        Terminate();
            50     void        Wait();
            51     STATUS         GetStatus();
            52     void         SetStatus(STATUS status);
            53     WHERE         GetWhere();
            54     void         SetWhere(WHERE where);
            55     static void *     NewThread(void *);
            56     virtual void     Run(void *param);
            57 protected:    
            58     NVHANDLE    _thrhand;
            59     STATUS        _status;
            60     WHERE        _where;
            61     void *        _param;
            62     void *        _void;
            63 };
            64 
            65 #define  THREAD_START(t)    (t).SetStatus(RUNNING); (t).SetWhere(HEAD);
            66 #define  THREAD_END(t)    (t).SetStatus(STOP); (t).SetWhere(TAIL);THREAD_DETACH;
            67 #define  THREAD_CONTINUE(t) ((t).GetStatus()== NVThread::RUNNING)?true:false
            68 
            69 #define THREAD_START_T    THREAD_START(*this)
            70 #define THREAD_END_T    THREAD_END(*this)
            71 #define THREAD_CONTINUE_T THREAD_CONTINUE(*this)
            72 
            73 
            74 
            75 #include "nvthread.i"
            76 
            77 #endif
            78 //--
            79 
             1 
             2 
             3 #include "nvthread.h"
             4 
             5 inline  
             6 NVThread::NVThread(){
             7     _where = TAIL;
             8     _status = STOP;
             9     
            10 }
            11 inline  
            12 NVThread::~NVThread(){
            13 }
            14 
            15 inline  
            16 bool NVThread::Create(void *param){
            17     bool ret;
            18     NVCreateThead(_thrhand,NVThread::NewThread,this,ret);
            19     if( ret){ //--線程創建成功,等待線程運行狀態改變
            20         while( GetStatus()!=NVThread::RUNNING){
            21             SLEEP_MSEC(100);
            22         }
            23     }
            24     return ret;
            25 }
            26 
            27 inline 
            28 void NVThread::Terminate(){
            29     _status = STOP;
            30 }
            31 
            32 inline 
            33 void * NVThread::NewThread(void *param){
            34     NVThread *thread = (NVThread *)param;
            35     THREAD_START(*thread);
            36     thread->Run(thread->_param);
            37     THREAD_END(*thread);
            38     return 0;
            39 }
            40 
            41 inline 
            42 void NVThread::Run(void *param){
            43 /*    while(THREAD_CONTINUE(*this)){
            44         Sleep(100);
            45     }    */
            46 }
            47 
            48 inline 
            49 void NVThread::Wait(){
            50     while(GetWhere()!=TAIL){
            51         SLEEP_MSEC(100);
            52     }
            53 }
            54 
            55 inline 
            56 NVThread::STATUS NVThread::GetStatus(){
            57     return _status;
            58 }
            59 
            60 inline 
            61 void NVThread::SetStatus(STATUS status){
            62     _status = status;
            63 }
            64 
            65 inline 
            66 NVThread::WHERE NVThread::GetWhere(){
            67     return _where;
            68 }
            69 
            70 inline 
            71 void NVThread::SetWhere(WHERE where){
            72     _where = where;
            73 }
            74 
            75 
            76 
            77 

            派生線程類實現分派外部全局函數
             1
             2#ifndef _THREADOBJECT_H
             3#define _THREADOBJECT_H
             4
             5/*
             6    file:    nvthreadobj.h
             7    class:     NVThreadObject
             8    desc:    控制外部線程行為
             9*/

            10
            11
            12#include "nvthread.h"
            13
            14class NVThreadObject:public NVThread{
            15public:
            16    void     Run(void *param){
            17        _threadproc(param);    
            18    }

            19    bool    Create(THREAD_PROC proc,void *param=0){
            20        _threadproc = proc;
            21        _param = param;
            22        return NVThread::Create();
            23    }

            24protected:    
            25    THREAD_PROC    _threadproc;
            26}
            ;
            27#endif
            posted @ 2006-03-11 00:24 放屁阿狗 閱讀(528) | 評論 (0)編輯 收藏

            準備辭職到通知領導不過2,3天的功夫
            實在不想去做實施那個ultra的破東西,整日跟客戶打交道,處人際關系小心謹慎的過活,一呆就是一整天。這種日子我定是受不了。
            領導給我分析就業形勢,就是勸我繼續留下,說是做行業實施比做開發吃香,做開發是吃青春飯的。
            呵呵,我可不是這么認為,只有開發水平上不去而被淘汰的人才會有這種想法。
            做開發,做編程一直是我的興趣。工作帶有自己的興趣便是工作就不是一種痛苦的責任了,我每天7小時睡眠,路上花2小時,吃飯加上其他時間一天有14小時左右是在computer之前。
            喜歡研究新的技術,看到或者聽到有某些技術出現,我都回去花大量時間去研究和編碼實踐,縱向橫向比較其優劣點,然后對其不足之處去修改或者自己重新實現自己的版本,結果就是使自己的眼睛越來越酸疼,老婆越來越多的嘮叨。
            我一直鼓勵別人多接觸開源社區,多看看一些軟件代碼,吸收其精髓來強身健體。
            有點扯遠了,繼續說我的工作。
            領導同意我的辭職,只是要求把登記公司的開發工作做完。
            工作其實也是簡單,在異構的系統環境中開發一些輔助性的軟件,大概8,9個之多。
            所以我現在還是繼續呆在公司,完成交待給我的工作。到今天,所有的開發已經差之無多了,因為我用了python(現在真是喜歡它,數據庫,用戶接口,分布式應用系統(ICE) 無所不能),過幾天估計就要去現場調試。
            其實我也挺喜歡這個工作環境,雖然剛剛被另外一家公司兼并,雖然跑了很多的人,雖然不加工資,雖然......
            接著我就得考慮找工作的問題,頭又開始有點大了。。。
            posted @ 2006-03-11 00:09 放屁阿狗 閱讀(322) | 評論 (0)編輯 收藏

            現在發現自己面試的心態很不好,不喜歡別人問東問西,問一些無關緊要的事情。討厭問一些膚淺的技術,比如老是有人問:"啊,了解多線程技術嗎","寫過socket網絡通信程序嗎?"....
            現在碰到面試的情況,我很是討厭讓我介紹自己,如何介紹,現在自己也不清楚。
            其實只要看我的工作簡歷和要求的工資待遇就可以看出我的能力了的,我是這樣想的。
            一次去面試,等了10分鐘,談了10分鐘,說是要等總監定奪,靠!騙我老遠來面試,很是不爽
            期待面試,我想找份收入高點的工作,畢竟現在這點錢只能維持養家糊口的水平,生活家庭的責任感越來越強烈;可是到了面試時候卻是打不起任何精神。
            posted @ 2006-03-02 01:10 放屁阿狗 閱讀(356) | 評論 (0)編輯 收藏

            vnc可是好東西,對linux的支持可是非常之優秀,比起在windows上要表現的好的多
            vnc采用c/s架構,其通信機制沒有多少的復雜,但是對編寫windows版本服務端代碼的開發者對windows api駕馭的能力倒是有點佩服
             其實現技術:
                  win-hook + event-simulate + gdi-bitmap-capture(delay send) + libjpeg + socket
            研究完了其工作機制之后我也寫了一個類vnc的服務器和客戶端程序,運行之后發現在頻率很高的bitmap捕獲到libjpeg的壓縮的過程很耗cpu資源,還有就是雖然采用jpeg壓縮(如在做視頻監控時采用的mjpeg設備一樣)還是于碼流太大,跟vnc比較了以下好像還是有一點的差距,畢竟不是當作一個正式的咚咚去做的,等有時間之后或者某人倡議之下繼續完善它吧!
            posted @ 2006-03-02 01:00 放屁阿狗 閱讀(3838) | 評論 (21)編輯 收藏


              1 #include <stdio.h>
              2 
              3 #include "jpeglib.h"
              4 
              5 void
              6 JpegInitDestination(j_compress_ptr cinfo)
              7 {
              8 }
              9 
             10 static boolean
             11 JpegEmptyOutputBuffer(j_compress_ptr cinfo)
             12 {    
             13     return TRUE;
             14 }
             15 
             16 static void
             17 JpegTermDestination(j_compress_ptr cinfo)
             18 {
             19 //    jpegDstDataLen = jpegDstBufferLen - jpegDstManager.free_in_buffer;
             20 }
             21 
             22 /**
             23     Raw Rgb Data converted to Jpeg data
             24 */
             25 bool JpegCompress(int w,int h,const char * rgb_data,int rgb_size,
             26                   char * jpeg_data,int *jpeg_size){
             27     struct jpeg_compress_struct cinfo;
             28     struct jpeg_error_mgr jerr;
             29     struct jpeg_destination_mgr jpegDstManager;
             30     int ret;
             31     unsigned char *srcBuf = new unsigned char[w * 3];
             32     JSAMPROW rowPointer[1];
             33     rowPointer[0= (JSAMPROW)srcBuf;
             34     int left_size;
             35     left_size = *jpeg_size;
             36     cinfo.err = jpeg_std_error(&jerr);
             37     jpeg_create_compress(&cinfo);
             38 
             39     cinfo.image_width = w;
             40     cinfo.image_height = h;
             41     cinfo.input_components = 3;
             42     cinfo.in_color_space = JCS_RGB;
             43     cinfo.raw_data_in = true;
             44     jpeg_set_defaults(&cinfo);
             45     
             46     
             47     cinfo.dest = &jpegDstManager;
             48     
             49     jpegDstManager.next_output_byte = (unsigned char*)jpeg_data;
             50     jpegDstManager.free_in_buffer = left_size;
             51     jpegDstManager.init_destination = JpegInitDestination;
             52     jpegDstManager.empty_output_buffer = JpegEmptyOutputBuffer;
             53     jpegDstManager.term_destination = JpegTermDestination;
             54         
             55     //jpeg_set_quality(&cinfo, 20, TRUE);
             56     
             57     jpeg_start_compress(&cinfo, TRUE);    
             58     for(int y=0;y< h;y++){
             59         rowPointer[0= (unsigned char*)(rgb_data + y*w*3);
             60         ret = jpeg_write_scanlines(&cinfo, rowPointer, 1);
             61     }
             62     jpeg_finish_compress(&cinfo);    
             63     jpeg_destroy_compress(&cinfo);    
             64     *jpeg_size = left_size - jpegDstManager.free_in_buffer;
             65     return true;
             66 }
             67 
             68 void
             69 JpegInitSource(j_decompress_ptr cinfo)
             70 {
             71 
             72 }
             73 
             74 boolean
             75 JpegFillInputBuffer(j_decompress_ptr cinfo)
             76 {
             77     /*
             78     jpegError = true;
             79     jpegSrcManager.bytes_in_buffer = jpegBufferLen;
             80     jpegSrcManager.next_input_byte = (JOCTET *)jpegBufferPtr;    */
             81     return TRUE;
             82 }
             83 
             84 void
             85 JpegSkipInputData(j_decompress_ptr cinfo, long num_bytes)
             86 {/*
             87     if (num_bytes < 0 || (size_t)num_bytes > jpegSrcManager.bytes_in_buffer) {
             88         jpegError = true;
             89         jpegSrcManager.bytes_in_buffer = jpegBufferLen;
             90         jpegSrcManager.next_input_byte = (JOCTET *)jpegBufferPtr;
             91     } else {
             92         jpegSrcManager.next_input_byte += (size_t) num_bytes;
             93         jpegSrcManager.bytes_in_buffer -= (size_t) num_bytes;
             94     }*/
             95 }
             96 
             97 void
             98 JpegTermSource(j_decompress_ptr cinfo)
             99 {
            100     /* No work necessary here. */
            101 }
            102 
            103 bool JpegUnCompress(const char * jpeg_data,int jpeg_size,
            104                     char *rgb_data,int rgb_size,int w,int h){
            105     struct jpeg_decompress_struct cinfo;
            106     struct jpeg_error_mgr jerr;
            107     struct jpeg_source_mgr jpegSrcManager;
            108     int ret;
            109     JSAMPROW rowPointer[1];
            110     cinfo.err = jpeg_std_error(&jerr);
            111     jpeg_create_decompress(&cinfo);
            112 
            113     jpegSrcManager.init_source = JpegInitSource;
            114     jpegSrcManager.fill_input_buffer = JpegFillInputBuffer;
            115     jpegSrcManager.skip_input_data = JpegSkipInputData;
            116     jpegSrcManager.resync_to_restart = jpeg_resync_to_restart;
            117     jpegSrcManager.term_source = JpegTermSource;
            118     jpegSrcManager.next_input_byte = (unsigned char*)jpeg_data;
            119     jpegSrcManager.bytes_in_buffer = jpeg_size;
            120     cinfo.src = &jpegSrcManager;
            121     
            122     jpeg_read_header(&cinfo, TRUE);
            123     cinfo.out_color_space = JCS_RGB;
            124     jpeg_start_decompress(&cinfo);
            125     if( cinfo.output_width != (unsigned int)w && cinfo.output_height != (unsigned int)h){
            126         jpeg_destroy_decompress(&cinfo);
            127         return false;
            128     }
            129     for (int dy = 0; cinfo.output_scanline < cinfo.output_height; dy++) {
            130         rowPointer[0= (unsigned char *)(rgb_data + w*dy*3);
            131         ret = jpeg_read_scanlines(&cinfo, rowPointer, 1);
            132     }
            133     jpeg_finish_decompress(&cinfo);        
            134     jpeg_destroy_decompress(&cinfo);        
            135     return true;
            136 }
            137 
            posted @ 2006-03-02 00:47 放屁阿狗 閱讀(8471) | 評論 (9)編輯 收藏

                 摘要:  1  2 #ifndef _BITMAP_H 3 #define _BITMAP_H 4  5 #include <windows.h> 6  7 void SaveImage(const cha...  閱讀全文
            posted @ 2006-03-02 00:45 放屁阿狗 閱讀(2381) | 評論 (0)編輯 收藏

                 摘要:  1 // VideoDrawer.h: interface for the CVideoDrawer class. 2 // 3 //////////////////////////////////////////////////////////////////////&nbs...  閱讀全文
            posted @ 2006-03-02 00:42 放屁阿狗 閱讀(1464) | 評論 (0)編輯 收藏

            僅列出標題
            共25頁: First 17 18 19 20 21 22 23 24 25 
            少妇内射兰兰久久| 美女久久久久久| 亚洲成av人片不卡无码久久| 久久久久四虎国产精品| 精品熟女少妇AV免费久久| 色8激情欧美成人久久综合电| 国产成人AV综合久久| 老司机国内精品久久久久| 久久午夜电影网| 精品水蜜桃久久久久久久| 99久久精品国产一区二区蜜芽| 亚洲国产精品一区二区久久| 久久久青草久久久青草| 成人国内精品久久久久影院VR| 狠狠色综合久久久久尤物 | 99久久免费国产特黄| 久久99国产综合精品免费| 国产V综合V亚洲欧美久久| 99久久国语露脸精品国产| 国产精品久久久天天影视香蕉| 精品国产青草久久久久福利| 亚洲国产成人久久精品99| 成人午夜精品久久久久久久小说| 国产99久久久国产精免费| 精品视频久久久久| 狠狠色狠狠色综合久久| …久久精品99久久香蕉国产| 国产精品成人99久久久久91gav| 精品久久人人爽天天玩人人妻| 久久经典免费视频| 久久久噜噜噜久久中文福利| 99久久99久久精品国产| 2021久久精品免费观看| 久久婷婷激情综合色综合俺也去| 婷婷久久五月天| 91久久精品91久久性色| 麻豆久久| 97久久精品人妻人人搡人人玩| 国内精品久久久久久久亚洲| 久久久久久伊人高潮影院| 久久久精品午夜免费不卡|