打開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 examlpeexample.Example().say_hello()注:如果導(dǎo)入模塊失敗,需要將模塊所在路徑添加到sys.path中,在次導(dǎo)入就會(huì)成功
摘要: UISearchBar控件就是要為你完成搜索功能的一個(gè)專用控件。它集成了很多你意想不到的功能和特點(diǎn)!首先,還是來普及一下UISearchBar控件API相關(guān)的屬性和方法吧!UISearchBar屬性相關(guān)_searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];// 初始化,不解釋 &nb...
摘要: 標(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ì) ...
正是由于這個(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
使用版本: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;
}
引文:
調(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
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);
第一步:
創(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)信息:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // Override point for customization after application launch.
- NSLog(@"\n ===> 程序開始 !");
-
- return YES;
- }
-
- - (void)applicationWillResignActive:(UIApplication *)application
- {
-
- NSLog(@"\n ===> 程序暫行 !");
- }
-
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
-
- NSLog(@"\n ===> 程序進(jìn)入后臺(tái) !");
- }
-
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
-
- NSLog(@"\n ===> 程序進(jìn)入前臺(tái) !");
- }
-
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- NSLog(@"\n ===> 程序重新激活 !");
-
- }
-
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- NSLog(@"\n ===> 程序意外暫行 !");
-
- UIDevice *device = [UIDevice currentDevice];
-
- }
首次運(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/
摘要: UIGestureRecognizer 是一個(gè)具體手勢(shì)的基類,提供了較為簡單的手勢(shì)實(shí)現(xiàn)方式 The concrete subclasses of UIGestureRecognizer are the following:UITapGestureRecognizerUIPinchGestureRecognizerUIRotationGestureRecog... 閱讀全文
在“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