PJSIP-PJLIB(samples) (the usage of the pjlib lib) (eg:string/I/O)
Here are some samples about PJLIB!
PJLIB is the basic lib of PJSIP, so we need master the lib first!
String:
In our project, string is often used.But in a project based on PJSIP,we should learn to use pj_str_t instead of C string.Of course there have lots functions for you to convert the string type.
First you should know the struct of pj_str_t,and you need to use the function of pj_str to creat a pj_str_t type from a normal C string.
And lots of function are same like the C/C++ stytle,you can use them easily if you know the C/C++.
//test for pjlib heat nan
// string
#include<pjlib.h>
#include<pj/string.h>
#include<stdio.h>
void compare(const pj_str_t* s1,const pj_str_t* s2)
{ pj_status_t status;
status=pj_strcmp(s1,s2);
if(status<)
{
printf("s1<s2\n");
}
else if(status==)
{
printf("s1=s2\n");
}
else
{
printf("s1>s2\n");
}
}
int main()
{
char *str="this is a string";
pj_status_t status;
pj_str_t s1,s2,s3;
status=pj_init();
if(status!=PJ_SUCCESS)
{
printf("pj_init failed\n");
}
s1=pj_str("helloworld");
s2=pj_str("heat nan"); printf("s1=%s\n",s1.ptr);
printf("s2=%s\n",s2.ptr);
printf("len1=%d;len2=%d\n",s1.slen,s2.slen);
//Create string initializer from a normal C string
//pj_str_t pj_str ( char * str )
printf("now we use the function pj_str creat a pj_str_t type string from normal C string");
s3=pj_str(str);
puts(s3.ptr);
printf("****************************************\n");
// //function pj_strcmp
printf("now we have a compare about the the two string!\n");
compare(&s1,&s2);
printf("****************************************\n"); pj_shutdown();
getchar();
return ; }
INPUT/OUTPUT:
FILE I/O:
Use the functions (eg pj_file_open,pj_file_read) operating the file.
Related documations :
http://www.pjsip.org/docs/latest/pjlib/docs/html/group__PJ__FILE__IO.htm
http://www.pjsip.org/docs/latest/pjlib/docs/html/group__PJ__FILE__ACCESS.htm
//PJLIB I/O
//file open
//heat nan
//describe: open the file and write "heat nan" in it;and then read from it
#include<pjlib.h>
#include<stdio.h>
#define FILENAME "helloworld.txt"
int main()
{
pj_status_t status;
pj_oshandle_t fd=;
pj_size_t length;
static char buffer[]={"heat nan!"};
char readbuffer[sizeof(buffer)+];
status=pj_init();//must
if(status!=PJ_SUCCESS)
{
printf("pj_init failed!\n");
}
PJ_LOG(,(" ","file open test")); if(pj_file_exists(FILENAME))
{
pj_file_delete(FILENAME);
} status=pj_file_open(NULL,FILENAME,PJ_O_WRONLY,&fd);
if(status!=PJ_SUCCESS)
{
PJ_LOG(,(" ","open file failed!"));
return ;
}
else
{
PJ_LOG(,(" ","file open successed!"));
} length=sizeof(buffer); status=pj_file_write(fd,buffer,&length);
if(status!=PJ_SUCCESS)
{
PJ_LOG(,(" ","write the file failed!"));
} pj_file_close(fd); //now we check the file weather exist
if(!pj_file_exists(FILENAME))
{
PJ_LOG(,(" ","Sorry! the file you want is not exist!"));
return ;
}
else
{
PJ_LOG(,(" ","Yeah! the file exist!"));
} // now we will show you the content of the file
status=pj_file_open(NULL,FILENAME,PJ_O_RDONLY,&fd);
if(status!=PJ_SUCCESS)
{
PJ_LOG(,(" ","open file failed!"));
}
length=;
while((pj_ssize_t)length<sizeof(readbuffer))
{
pj_ssize_t read;
read=;
status=pj_file_read(fd,&readbuffer[length],&read);
if(status!=PJ_SUCCESS)
{
PJ_LOG(,(" ","read the file failed!"));
return ;
}
if(read==)//EOF the end of the text
{
break;
}
length+=read; }
puts(readbuffer);
pj_shutdown();
getchar(); }
PJSIP-PJLIB(samples) (the usage of the pjlib lib) (eg:string/I/O)的更多相关文章
- 学习一下 JVM (二) -- 学习一下 JVM 中对象、String 相关知识
一.JDK 8 版本下 JVM 对象的分配.布局.访问(简单了解下) 1.对象的创建过程 (1)前言 Java 是一门面向对象的编程语言,程序运行过程中在任意时刻都可能有对象被创建.开发中常用 new ...
- IOS 之 PJSIP 笔记(一) 编译多平台支持的静态库
好久没有写博客了,这也算是我步入新工作后的第一篇技术博文吧.在进入新公司前,早就有了技术层进入下一个迭代的准备,但很多事情是意想不到的,就像我以 C# 程序员的身份面试入职的,而今却是一个全职的 IO ...
- IOS 之 PJSIP 笔记(二) iPJSUA 的简单使用
上一篇在编译完之后,就很不负责的结束了,本篇就对 PJSIP 库中提供的一个示例 iPJSUA 的使用,做一个简单的介绍.也能解除很多人对官方文档的一个困扰,起码我是被困扰过了. 首先,要确保你的 P ...
- CUDA Samples: Streams' usage
以下CUDA sample是分别用C++和CUDA实现的流的使用code,并对其中使用到的CUDA函数进行了解说,code参考了<GPU高性能编程CUDA实战>一书的第十章,各个文件内容如 ...
- (转载)android:android.content.res.Resources$NotFoundException: String resource ID #..
android.content.res.Resources$NotFoundException: String resource ID #0x0 找不到资源文件ID #0x0 原因分析如下: 遇到这种 ...
- (1)Python3笔记 数据类型之Number与String
一.Number(数值) 1) 整数 : int 2) 浮点数: float type(1) //int type(1.0) // float type(1+1) // int , 2 type(1+ ...
- Appfuse搭建过程(下源代码不须要maven,lib直接就在项目里(否则痛苦死!))
什么是Appfuse:AppFuse是一个集成了众多当前最流行开源框架与工具(包含Hibernate.ibatis.Struts.Spring.DBUnit.Maven.Log4J.Struts Me ...
- Java学习笔记(5)--- Number类和Math 类,String类的应用,Java数组入门
1.Number 和 Math 类: 在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类型(int,double,float这些)的情形. 这种由编译器特别支持的包装称为装箱,所以当内置数 ...
- 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)
题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...
随机推荐
- MySQL的基础(优化)1
1,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度设得尽可能小 2,在可能的情况下,应该尽量把字段设置为NOT NULL,这样在将来执行查询的时候,数据库不用去比较NULL值 3,对于某 ...
- Linux 信号表 signals
Linux支持POSIX reliable signals和POSIX real-time signals. 信号处理 进程接受到信号之后会有一些默认的处理方式,如下为5种处理方式: type des ...
- 笨办法学Python(三十三)
习题 33: While 循环 接下来是一个更在你意料之外的概念: while-loop``(while 循环).``while-loop 会一直执行它下面的代码片段,直到它对应的布尔表达式为 Fal ...
- Cydia Tweak--Cydia Substrate
http://www.jianshu.com/p/8982e9670fc6 Cydia Substrate.MobileHooker MSHookMessageEx MSHookFunction Mo ...
- 前端高质量知识(一)-JS内存空间详细图解
变量对象与堆内存 var a = 20; var b = 'abc'; var c = true; var d = { m: 20 } 因为JavaScript具有自动垃圾回收机制,所 ...
- ACM Arabella Collegiate Programming Contest 2015 H. Capital City 边连通分量
题目链接:http://codeforces.com/gym/100676/attachments 题意: 有 n 个点,m 条边,图中,边强连通分量之间可以直达,即距离为 0 ,找一个点当做首都,其 ...
- express_webpack自动刷新
现在,webpack可以说是最流行的模块加载器(module bundler).一方面,它为前端静态资源的组织和管理提供了相对较完善的解决方案,另一方面,它也很大程度上改变了前端开发的工作流程.在应用 ...
- Swiper插件
中文官网:Swiper中文网 英文:英文网 此插件功能比较强大,网页端.手机端都可以使用的插件.这里记录一下在微信h5页面里面滑动获取数据. 先下载css和js,引用到项目中 这里有6个节点,没划一个 ...
- C# 操作符与表达式
C#保留了C++所有的操作符,其中指针操作符(*和->)与引用操作符(&)需要有unsafe的上下文.C#摈弃了范围辨析操作符(::),一律改为单点操作符(.).我们不再阐述那些保留的C ...
- centos 7忘记了root密码,如何改密码?
今天服务器突然进不去了,不知道是密码被改了,还是什么情况! 服务器版本:centos 7.0 网上查找了很多文档,有些办法不可行,如果是亲自试过绝对可行的方法: 1:重启服务器,如下界面,按键盘 &q ...