• <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>
            面對現實,超越自己
            逆水行舟,不進則退
            posts - 269,comments - 32,trackbacks - 0
            一、SWIG環境搭建
             
               1、 下載Swig for Windows:http://www.swig.org/download.html
               2、 解壓 .zip 文件到目錄,比如:D:\backupsoftware
               3、 添加環境變量到path, 比如: D:\backupsoftware\swigwin-3.0.10
               4、 簡單測試安裝是否成功:
               打開Dos,在命令行執行: swig --help, 顯示 Target Language Options即表明安裝成功。

            二、以c++為例

            1、編寫c++源文件
            //example.h
            #include <iostream>
            using namespace std;
            class Example{
            public:
            void say_hello();
            };

            //example.cpp

            #include "example.h"

            void Example::say_hello()
            {
                  printf("hello");
            }

            2、再寫一個swig模塊定義文件如下
            %module example
            %{
            #include "example.h"
            %}
            %include "example.h"

            3、通過命令行運行:$ swig -python -c++ example.i

                如果是使用C源碼,則選項:$ swig -Python example.i

                這樣會創建兩個不同的文件:example_wrap.cxx(如果用c源碼是example_wrap.c),和python文件example.py。


            4、使用python.distutils生成模塊動態庫
            python自帶一個distutils工具,可以用它來創建python的擴展模塊。使用它也很簡單,只需要先定義一個配置文件,通常是命名為setup.py,如下:
            #!/usr/bin/env python

            """
            setup.py file for SWIG C\+\+/Python example
            """
            from distutils.core import setup, Extension
            example_module = Extension('_example',
            sources=['example.cpp''example_wrap.cxx',],
            )
            setup (name = 'example',
            version = '0.1',
            author = "www",
            description = """Simple swig C\+\+/Python example""",
            ext_modules = [example_module],
            py_modules = ["example"],
            )

            注:swig生成的擴展模塊對象名必須使用python模塊名并在前面加上下劃線_,剛才我們通過swig生成的python文件是example.py,所以這里的模塊對象名必須是'_example',否則無法順利編譯。

            5、編譯
            命令行中將當前工作目錄切換到文件example.cpp,example_wrap.cxx,example.py,setup.py所在的目錄,然后輸入以下命令:
            python setup.py build_ext --inplace

            會在本目錄下生成_example.pyd模塊。

            6、測試
            import examlpe
            example.Example().say_hello()

            :如果導入模塊失敗,需要將模塊所在路徑添加到sys.path中,在次導入就會成功



            posted @ 2016-08-18 11:20 王海光 閱讀(4697) | 評論 (0)編輯 收藏
                 摘要: UISearchBar控件就是要為你完成搜索功能的一個專用控件。它集成了很多你意想不到的功能和特點!首先,還是來普及一下UISearchBar控件API相關的屬性和方法吧!UISearchBar屬性相關_searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];// 初始化,不解釋 &nb...  閱讀全文
            posted @ 2015-03-04 19:23 王海光 閱讀(872) | 評論 (0)編輯 收藏
                 摘要: 標準庫C++標準庫,包括了STL容器,算法和函數等。C++ Standard Library:是一系列類和函數的集合,使用核心語言編寫,也是C++ISO自身標準的一部分。Standard Template Library:標準模板庫C POSIX library : POSIX系統的C標準庫規范ISO C++ Standards Committee :C++標準委員會 ...  閱讀全文
            posted @ 2014-11-14 08:58 王海光 閱讀(2431) | 評論 (0)編輯 收藏
            不知道大家有沒有我這種體驗.大家先看看下面這段代碼:
            int fp=_wopen(L"Hello.dat",O_BINARY | O_CREAT | O_TRUNC | O_RDWR);
            if(fp==-1) return;
            write(fp,L"123中國人",wcslen(L"123中國人"));
            close(fp);

            上面這段代碼不知道大家看出什么BUG來了.如果大家看不出毛病也不足為怪,因為這是我們的習慣導致了我們的錯誤產生.


            先讓我來分析一下write吧.下面是write的原型:
            int write( int handle, const void *buffer, unsigned int count );
            參數:
            handle   已打開或已創建的文件句柄
            buffer     待寫入的數據
            count     待寫入的數據大小
            現在分析為什么上面的那代碼有bug,其實主要問題就在一個buffer,和count.
            如果我們寫入一個Ansi字符串,上面的代碼改成相應的形式確實沒有錯.
            但如果是寫入一個寬字符串,那么上面的代碼就不嚴格.原因就在于count.

            我們首先看一下strlen和wcslen,如果使用strlen,一般情況下,我們直接作為字符串的長度,
            而使用wcslen,你會發現,得出的不是字符串的長度而是字符的個數.

            這就是問題的所在.一般情況下.char的長度是1,這是用sizeof(char)運算出來的結果.
            len=strlen(str)*sizeof(char);而我們一般情況下,都只用strlen(str)來等價,這就是平時的習慣.
            正是由于這個習慣所引來的問題,這個習慣并不適用于寬字符串.因為wcslen(str)*sizeof(wchar_t)并不等于wcslen(strl).這就是習慣所引起的錯誤.

            說到這里我想大家都明白了.我在這里把這種習慣稱之為不良習慣.所以大家以后在計算字符串長度的時候,千萬不能簡而簡之,一定要len=strlen(str)*sizeof(char),len=wcslen(str)*sizeof(wchar_t).
            不要再犯這種習慣性的低級錯誤.

            本文轉自:http://blog.csdn.net/aylixuan/article/details/6130820
            posted @ 2014-10-10 11:53 王海光 閱讀(3817) | 評論 (0)編輯 收藏
            使用版本:1.1.10

            今天弄了一下Gloox中自帶的收發文件例子,收發文件的例子都是好使的,只不過,在調試過程中需要注意一些問題,下面將我遇到的問題做個記錄(例子中以In-Band Bytestreams方式收發)

            1、發送文件過程中遇到404錯誤
            <iq type='error' id='uid-8509a748-00000005' to='wanghaiguang@wanghaiguang-wk/glooxsendfile'from='www@192.168.60.67/Spark 2.6.3'><sixmlns='http://jabber.org/protocol/si' id='uid-8509a748-00000006' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='d:\offline.bmp' size='6998'/><feature xmlns='http://jabber.org/protocol/feature-neg'><x xmlns='jabber:x:data' type='form'><field type='list-single'var='stream-method'><option label='ibb'><value>http://jabber.org/protocol/ibb</value></option><option label='oob'><value>jabber:iq:oob</value></option><option label='s5b'><value>http://jabber.org/protocol/bytestreams</value></option><value/></field></x></feature></si><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>

            可以將ip地址換成服務器名稱試試
            JID j( "www@192.168.60.67/gloox" );——> JID j( "www@wanghaiguang-wk/gloox" );

            2、
            發送文件過程中遇到503錯誤
            <iq type='error' id='uid-8663a748-00000005' from='www@wanghaiguang-wk/glooxsend'to='wanghaiguang@wanghaiguang-wk/glooxsendfile'><si xmlns='http://jabber.org/protocol/si' id='uid-8663a748-00000006' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='d:\offline.bmp' size='6998'/><feature xmlns='http://jabber.org/protocol/feature-neg'><x xmlns='jabber:x:data' type='form'><field type='list-single' var='stream-method'><option label='ibb'><value>http://jabber.org/protocol/ibb</value></option><option label='oob'><value>jabber:iq:oob</value></option><option label='s5b'><value>http://jabber.org/protocol/bytestreams</value></option><value/></field></x></feature></si><error code='503' type='cancel'><service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>

            這個問題可能是由于你接收端的資源名稱與發送端不匹配
            //接收端登錄的jid
            JID jid( "www@192.168.60.67/glooxsendfile" );
             j = new Client( jid, "111" );

            //發送端的jid名稱(發送給對方的jid名稱)
            JID j( "www@wanghaiguang-wk/gloox" );
            if( j.resource().empty() )
            {
                 printf( "error: need full jid\n" );
                 return 1;
            }
            posted @ 2014-09-02 17:18 王海光 閱讀(2471) | 評論 (0)編輯 收藏

            引文:

            調試GLOOX 1.0.10的注冊功能頗費了一些功夫。總體邏輯如GLOOX自帶的例子一樣是毫無疑問的,但是照搬例子又是不能完成注冊的,返回錯誤碼為4------RegistrationBadRequest筆者一開始在網上狂搜解決方案,資料少之又少,有建議重寫Client::handleNormalNode函數(目的是禁止SASL認證)的,有直接繼承Client重寫Client::handleNormalNode函數的,但都沒說到點子上。經過一段時間的研究,在GLOOX的maillist上得到啟發,順利完成注冊。現將解決方案記錄下來:


            環境

            客戶端:GLOOX1.0.1.0 VS2008

            服務器:OPENFIRE 默認安裝


            對于GLOOX自帶的注冊例子不能正常注冊的問題有人在郵件列表里提出來。一個哥們這樣回答:

            Ok, I've found what the problem was 
            In openFire server parameters, Anonymous Login => Disabled !!! 

            意思是要禁用openFire服務器里的選項”注冊和登錄“的”匿名登錄“項

            筆者按此說明禁用該選項,果然注冊成功。

            這說明開始的注冊失敗是和匿名登錄有關系的。我們來看一下引用registration_expmple例子登錄失敗時的XML流:

            S->C:服務器返回給客戶端支持的認證機制:

            <stream:features xmlns:stream='http://etherx.jabber.org/streams'><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><auth xmlns='http://jabber.org/features/iq-auth'/><register xmlns='http://jabber.org/features/iq-register'/></stream:features> 

             

            從上面XML流中我們可以看到,默認openFire支持四種認證機制,分別是:DIGEST-MD5、PLAIN、ANONYMOUS、CRAM-MD5。然后我們看GLOOX客戶端的響應流:

            C->S:客戶端返回選擇的認證方式:

            <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS'/>

            可以看出,客戶端”無恥“的選擇了”匿名“--
            'ANONYMOUS'方式

            接下來的流程就是客戶端”無恥“的選擇了以匿名的方式登錄了服務器,然后再發送注冊請求,請求如下:

            <iq id='uid:4e69eccd:00006784' type='set' from='447e0585@zxl/447e0585' xmlns='jabber:client'><query xmlns='jabber:iq:register'><username>bbaxiao</username><password>123456</password><name>test2</name><email>163@gmail.com</email></query></iq> 

            我們看到,IQ節里包含“form”屬性,即客戶端匿名身份標識。

            注意,一個客戶端已經以一個身份(由服務器臨時分配的一個JID)登錄,建立了會話,在服務器上我們會看到這個會話,并且服務器發送心跳一直維護這個會話。這種情況下,這個客戶端再發送注冊請求(另一個身份)建立與服務器的連接是不被允許的。具體請參考XEP-0077(In-Band Registration):我們關注這兩段:

            If the entity cancels its registration with its "home" server (i.e., the server at which it has maintained its XMPP account), then the entity SHOULD NOT include a 'from' or 'to' address in the remove request the server SHOULD then return a <not-authorized/> stream error and terminate all active sessions for the entity. The server SHOULD perform the remove based on the bare JID <localpart@domain.tld> associated with the current session or connection over which it received the remove request. If the server is an instant messaging and presence server that conforms to XMPP IM [8], the server SHOULD also cancel all existing presence subscriptions related to that entity (as stored in the entity's roster). 
             
            If the entity cancels its registration with a service other than its home server, its home server MUST stamp a 'from' address on the remove request, which in accordance with XMPP Core will be the entity's full JID <localpart@domain.tld/resource>. The service MUST perform the remove based on the bare JID <localpart@domain.tld> portion of the 'from' address. 

            If the entity cancels its registration with its "home" server (i.e., the server at which it has maintained its XMPP account), then the entity SHOULD NOT include a 'from' or 'to' address in the remove request the server SHOULD then return a <not-authorized/> stream error and terminate all active sessions for the entity. The server SHOULD perform the remove based on the bare JID <localpart@domain.tld> associated with the current session or connection over which it received the remove request. If the server is an instant messaging and presence server that conforms to XMPP IM [8], the server SHOULD also cancel all existing presence subscriptions related to that entity (as stored in the entity's roster).  
              
            If the entity cancels its registration with a service other than its home server, its home server MUST stamp a 'from' address on the remove request, which in accordance with XMPP Core will be the entity's full JID <localpart@domain.tld/resource>. The service MUST perform the remove based on the bare JID <localpart@domain.tld> portion of the 'from' address.  

             

            意思是說注冊請求不能包含“from”屬性。

            正常的注冊流如下:

            <iq id='uid:4e69eccd:00003d6c' type='set' xmlns='jabber:client'><query xmlns='jabber:iq:register'><username>bbaxiao</username><password>123456</password><name>test2</name><email>163@gmail.com</email></query></iq> 

            ---------------------------

            綜上所述,解決方案如下:

            一、關閉openFire的匿名登錄功能。^_^……

            二、禁止GLOOX匿名認證功能。

            file:client.cpp 
             
            fun: int Client::getSaslMechs( Tag* tag ) 
             
            line:423 
             
            //將423行注釋掉即可。 
            422:if( tag->hasChildWithCData( mech, "ANONYMOUS" ) ) 
            423      //mechs |= SaslMechAnonymous; 

            重新編譯生成DLL即可。

            三、手動設置GLOOX客戶端SASL認證機制

            在調用j->connect()之前設置SASL認證機制,比如設置為“DIGEST-MD5”


            j->setSASLMechanisms(SaslMechDigestMd5);

            這種方式的缺點是需要先確定服務器支持的認證機制。

            四、根據XEP-0077所述,即使其名登錄,注冊流只要不帶“from”屬性應該也可以。所以我們要處理發出的注冊流,去除“from”屬性重新發送注冊流即可。


            本文轉自:http://blog.csdn.net/abcpanpeng/article/details/7370974


            posted @ 2014-08-28 17:59 王海光 閱讀(1536) | 評論 (0)編輯 收藏
            NSString中如果包括中文字符,在轉換為NSURL時得到的值為nil

            解決辦法:
            NSString *urlString = [NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?q=%@&units=imperial",cityName];
            urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            NSURL *url = [NSURL URLWithString:urlString];
            NSLog(@"%@", url);
            posted @ 2014-08-18 09:45 王海光 閱讀(1689) | 評論 (0)編輯 收藏
            第一步:
            創建2個NSNotificationCenter監聽
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
            name:UIApplicationWillResignActiveNotification object:nil]; //監聽是否觸發home鍵掛起程序.
                
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:)
            name:UIApplicationDidBecomeActiveNotification object:nil]; //監聽是否重新進入程序程序.
            


            第二步:
            實現2個NSNotificationCenter所觸發的事件方法
            - (void)applicationWillResignActive:(NSNotification *)notification
            {
                printf("按理說是觸發home按下\n");
            }
            - (void)applicationDidBecomeActive:(NSNotification *)notification
            {
                printf("按理說是重新進來后響應\n");
            }
            


            注: 在home鍵觸發后,AppDelegate響應的方法為:

            - (void)applicationDidEnterBackground:(UIApplication *)application { /* Use this method to release shared resources, save user data, invalidate timers,

            and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. */ }

            本文轉自:http://blog.csdn.net/sqc3375177/article/details/9466687

            其他相關信息:
            1. (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
            2.  
            3.     // Override point for customization after application launch.  
            4.     NSLog(@"\n ===> 程序開始 !");   
            5.       
            6.     return YES;  
            7.  
            8.                               
            9. (void)applicationWillResignActive:(UIApplication *)application  
            10.  
            11.       
            12.     NSLog(@"\n ===> 程序暫行 !");   
            13.  
            14.   
            15. (void)applicationDidEnterBackground:(UIApplication *)application  
            16.  
            17.       
            18.      NSLog(@"\n ===> 程序進入后臺 !");   
            19.  
            20.   
            21. (void)applicationWillEnterForeground:(UIApplication *)application  
            22.  
            23.       
            24.      NSLog(@"\n ===> 程序進入前臺 !");   
            25.  
            26.   
            27. (void)applicationDidBecomeActive:(UIApplication *)application  
            28.  
            29.     NSLog(@"\n ===> 程序重新激活 !");   
            30.       
            31.  
            32.   
            33. (void)applicationWillTerminate:(UIApplication *)application  
            34.  
            35.     NSLog(@"\n ===> 程序意外暫行 !");   
            36.   
            37.     UIDevice *device [UIDevice currentDevice];  
            38.       
            39.  
             

            首次運行

            - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

            - (void)applicationDidBecomeActive:(UIApplication *)application

             

            首次關閉(home):

            - (void)applicationWillResignActive:(UIApplication *)application

            - (void)applicationDidEnterBackground:(UIApplication *)application

             

            再次運行:

            - (void)applicationWillEnterForeground:(UIApplication *)application

            - (void)applicationDidBecomeActive:(UIApplication *)application

             

            再次關閉:

            - (void)applicationWillResignActive:(UIApplication *)application

            - (void)applicationDidEnterBackground:(UIApplication *)application


            本文轉自:http://friendlysong.blog.163.com/blog/static/3225243920128144251666/
            posted @ 2014-08-01 13:31 王海光 閱讀(2357) | 評論 (0)編輯 收藏
                 摘要: UIGestureRecognizer 是一個具體手勢的基類,提供了較為簡單的手勢實現方式  The concrete subclasses of UIGestureRecognizer are the following:UITapGestureRecognizerUIPinchGestureRecognizerUIRotationGestureRecog...  閱讀全文
            posted @ 2014-07-29 13:35 王海光 閱讀(2013) | 評論 (0)編輯 收藏
            “Header Search Paths” 中添加“/usr/include/libxml2″
            “Other Linker Flags”添加“-lxml2″ 
            運行后出現錯誤找不到<libxml/tree.h>

             解決辦法:“Header Search Paths” 中添加 ${SDKROOT}/usr/include/libxml2
            posted @ 2014-07-15 13:50 王海光 閱讀(1126) | 評論 (0)編輯 收藏
            僅列出標題  下一頁
            精品国际久久久久999波多野| 99久久香蕉国产线看观香| 香蕉久久夜色精品国产2020| 四虎国产精品免费久久5151| www.久久热.com| 国产精品无码久久久久久| 国内精品久久久久影院优| 久久久久亚洲AV无码专区体验| 久久亚洲AV无码精品色午夜| 久久久久久久女国产乱让韩 | 精品久久久久久无码国产| 久久777国产线看观看精品| 久久精品国产福利国产秒| 精品一区二区久久久久久久网站| 亚洲狠狠综合久久| 久久久无码精品午夜| 久久精品国产免费观看| 人妻少妇久久中文字幕| 久久综合丝袜日本网| 欧美亚洲另类久久综合婷婷| 久久经典免费视频| 国内精品久久久人妻中文字幕| 国产AV影片久久久久久| 伊人色综合久久天天网| 91久久婷婷国产综合精品青草| 久久99国产精品成人欧美| 久久久久久久久久久精品尤物| 精品熟女少妇a∨免费久久| 久久精品国产只有精品66 | 精品综合久久久久久888蜜芽| 国产精品久久久久…| 久久久久亚洲精品男人的天堂| 精品人妻伦九区久久AAA片69| 国产Av激情久久无码天堂| 亚洲伊人久久综合影院| 国内精品久久久久伊人av| 日韩AV毛片精品久久久| 久久久久人妻精品一区| 污污内射久久一区二区欧美日韩| 国内精品久久久久伊人av| 午夜精品久久久久|