• <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>
            面對(duì)現(xiàn)實(shí),超越自己
            逆水行舟,不進(jìn)則退
            posts - 269,comments - 32,trackbacks - 0
            一、SWIG環(huán)境搭建
             
               1、 下載Swig for Windows:http://www.swig.org/download.html
               2、 解壓 .zip 文件到目錄,比如:D:\backupsoftware
               3、 添加環(huán)境變量到path, 比如: D:\backupsoftware\swigwin-3.0.10
               4、 簡單測試安裝是否成功:
               打開Dos,在命令行執(zhí)行: 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、再寫一個(gè)swig模塊定義文件如下
            %module example
            %{
            #include "example.h"
            %}
            %include "example.h"

            3、通過命令行運(yùn)行:$ swig -python -c++ example.i

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

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


            4、使用python.distutils生成模塊動(dòng)態(tài)庫
            python自帶一個(gè)distutils工具,可以用它來創(chuàng)建python的擴(kuò)展模塊。使用它也很簡單,只需要先定義一個(gè)配置文件,通常是命名為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生成的擴(kuò)展模塊對(duì)象名必須使用python模塊名并在前面加上下劃線_,剛才我們通過swig生成的python文件是example.py,所以這里的模塊對(duì)象名必須是'_example',否則無法順利編譯。

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

            會(huì)在本目錄下生成_example.pyd模塊。

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

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



            posted @ 2016-08-18 11:20 王海光 閱讀(4714) | 評(píng)論 (0)編輯 收藏
                 摘要: UISearchBar控件就是要為你完成搜索功能的一個(gè)專用控件。它集成了很多你意想不到的功能和特點(diǎn)!首先,還是來普及一下UISearchBar控件API相關(guān)的屬性和方法吧!UISearchBar屬性相關(guān)_searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];// 初始化,不解釋 &nb...  閱讀全文
            posted @ 2015-03-04 19:23 王海光 閱讀(881) | 評(píng)論 (0)編輯 收藏
                 摘要: 標(biāo)準(zhǔn)庫C++標(biāo)準(zhǔn)庫,包括了STL容器,算法和函數(shù)等。C++ Standard Library:是一系列類和函數(shù)的集合,使用核心語言編寫,也是C++ISO自身標(biāo)準(zhǔn)的一部分。Standard Template Library:標(biāo)準(zhǔn)模板庫C POSIX library : POSIX系統(tǒng)的C標(biāo)準(zhǔn)庫規(guī)范ISO C++ Standards Committee :C++標(biāo)準(zhǔn)委員會(huì) ...  閱讀全文
            posted @ 2014-11-14 08:58 王海光 閱讀(2447) | 評(píng)論 (0)編輯 收藏
            不知道大家有沒有我這種體驗(yàn).大家先看看下面這段代碼:
            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來了.如果大家看不出毛病也不足為怪,因?yàn)檫@是我們的習(xí)慣導(dǎo)致了我們的錯(cuò)誤產(chǎn)生.


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

            我們首先看一下strlen和wcslen,如果使用strlen,一般情況下,我們直接作為字符串的長度,
            而使用wcslen,你會(huì)發(fā)現(xiàn),得出的不是字符串的長度而是字符的個(gè)數(shù).

            這就是問題的所在.一般情況下.char的長度是1,這是用sizeof(char)運(yùn)算出來的結(jié)果.
            len=strlen(str)*sizeof(char);而我們一般情況下,都只用strlen(str)來等價(jià),這就是平時(shí)的習(xí)慣.
            正是由于這個(gè)習(xí)慣所引來的問題,這個(gè)習(xí)慣并不適用于寬字符串.因?yàn)?/span>wcslen(str)*sizeof(wchar_t)并不等于wcslen(strl).這就是習(xí)慣所引起的錯(cuò)誤.

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

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

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

            1、發(fā)送文件過程中遇到404錯(cuò)誤
            <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地址換成服務(wù)器名稱試試
            JID j( "www@192.168.60.67/gloox" );——> JID j( "www@wanghaiguang-wk/gloox" );

            2、
            發(fā)送文件過程中遇到503錯(cuò)誤
            <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>

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

            //發(fā)送端的jid名稱(發(fā)送給對(duì)方的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 王海光 閱讀(2480) | 評(píng)論 (0)編輯 收藏

            引文:

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


            環(huán)境

            客戶端:GLOOX1.0.1.0 VS2008

            服務(wù)器:OPENFIRE 默認(rèn)安裝


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

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

            意思是要禁用openFire服務(wù)器里的選項(xiàng)”注冊(cè)和登錄“的”匿名登錄“項(xiàng)。

            筆者按此說明禁用該選項(xiàng),果然注冊(cè)成功。

            這說明開始的注冊(cè)失敗是和匿名登錄有關(guān)系的。我們來看一下引用registration_expmple例子登錄失敗時(shí)的XML流:

            S->C:服務(wù)器返回給客戶端支持的認(rèn)證機(jī)制:

            <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流中我們可以看到,默認(rèn)openFire支持四種認(rèn)證機(jī)制,分別是:DIGEST-MD5、PLAIN、ANONYMOUS、CRAM-MD5。然后我們看GLOOX客戶端的響應(yīng)流:

            C->S:客戶端返回選擇的認(rèn)證方式:

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

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

            接下來的流程就是客戶端”無恥“的選擇了以匿名的方式登錄了服務(wù)器,然后再發(fā)送注冊(cè)請(qǐng)求,請(qǐng)求如下:

            <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節(jié)里包含“form”屬性,即客戶端匿名身份標(biāo)識(shí)。

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

            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.  

             

            意思是說注冊(cè)請(qǐng)求不能包含“from”屬性。

            正常的注冊(cè)流如下:

            <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> 

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

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

            一、關(guān)閉openFire的匿名登錄功能。^_^……

            二、禁止GLOOX匿名認(rèn)證功能。

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

            重新編譯生成DLL即可。

            三、手動(dòng)設(shè)置GLOOX客戶端SASL認(rèn)證機(jī)制

            在調(diào)用j->connect()之前設(shè)置SASL認(rèn)證機(jī)制,比如設(shè)置為“DIGEST-MD5”


            j->setSASLMechanisms(SaslMechDigestMd5);

            這種方式的缺點(diǎn)是需要先確定服務(wù)器支持的認(rèn)證機(jī)制。

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


            本文轉(zhuǎn)自:http://blog.csdn.net/abcpanpeng/article/details/7370974


            posted @ 2014-08-28 17:59 王海光 閱讀(1547) | 評(píng)論 (0)編輯 收藏
            NSString中如果包括中文字符,在轉(zhuǎn)換為NSURL時(shí)得到的值為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 王海光 閱讀(1700) | 評(píng)論 (0)編輯 收藏
            第一步:
            創(chuàng)建2個(gè)NSNotificationCenter監(jiān)聽
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
            name:UIApplicationWillResignActiveNotification object:nil]; //監(jiān)聽是否觸發(fā)home鍵掛起程序.
                
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:)
            name:UIApplicationDidBecomeActiveNotification object:nil]; //監(jiān)聽是否重新進(jìn)入程序程序.
            


            第二步:
            實(shí)現(xiàn)2個(gè)NSNotificationCenter所觸發(fā)的事件方法
            - (void)applicationWillResignActive:(NSNotification *)notification
            {
                printf("按理說是觸發(fā)home按下\n");
            }
            - (void)applicationDidBecomeActive:(NSNotification *)notification
            {
                printf("按理說是重新進(jìn)來后響應(yīng)\n");
            }
            


            注: 在home鍵觸發(fā)后,AppDelegate響應(yīng)的方法為:

            - (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. */ }

            本文轉(zhuǎn)自:http://blog.csdn.net/sqc3375177/article/details/9466687

            其他相關(guān)信息:
            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 ===> 程序進(jìn)入后臺(tái) !");   
            19.  
            20.   
            21. (void)applicationWillEnterForeground:(UIApplication *)application  
            22.  
            23.       
            24.      NSLog(@"\n ===> 程序進(jìn)入前臺(tái) !");   
            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.  
             

            首次運(yùn)行

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

            - (void)applicationDidBecomeActive:(UIApplication *)application

             

            首次關(guān)閉(home):

            - (void)applicationWillResignActive:(UIApplication *)application

            - (void)applicationDidEnterBackground:(UIApplication *)application

             

            再次運(yùn)行:

            - (void)applicationWillEnterForeground:(UIApplication *)application

            - (void)applicationDidBecomeActive:(UIApplication *)application

             

            再次關(guān)閉:

            - (void)applicationWillResignActive:(UIApplication *)application

            - (void)applicationDidEnterBackground:(UIApplication *)application


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

             解決辦法:“Header Search Paths” 中添加 ${SDKROOT}/usr/include/libxml2
            posted @ 2014-07-15 13:50 王海光 閱讀(1136) | 評(píng)論 (0)編輯 收藏
            僅列出標(biāo)題
            共27頁: 1 2 3 4 5 6 7 8 9 Last 
            夜夜亚洲天天久久| 99久久国语露脸精品国产| 久久国产精品无码网站| 国产精品女同一区二区久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久99国产精品久久| 精品伊人久久大线蕉色首页| 久久综合色老色| 久久亚洲精品人成综合网| AAA级久久久精品无码区| 国产精品久久久久久久app | 久久影院综合精品| 久久99国产亚洲高清观看首页| 久久亚洲AV无码精品色午夜 | 要久久爱在线免费观看| 久久精品国产亚洲麻豆| 久久国产福利免费| 国内精品伊人久久久久av一坑 | 99久久免费国产精精品| 久久久久亚洲爆乳少妇无| 日韩乱码人妻无码中文字幕久久 | 人妻丰满AV无码久久不卡| 久久香蕉国产线看观看99| 久久久久99这里有精品10 | 亚洲国产精品无码久久一线| 99久久精品免费看国产| 久久综合九色综合网站| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 中文精品久久久久人妻不卡| 国内精品久久久久影院优| 亚洲精品无码专区久久同性男| 久久这里都是精品| 91精品婷婷国产综合久久| 2021国内精品久久久久久影院| 免费久久人人爽人人爽av| 久久免费国产精品| 亚洲国产成人久久精品动漫| 麻豆一区二区99久久久久| 一本久久免费视频| 亚洲精品国产美女久久久| 久久久久久精品无码人妻|