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尽可能多,任意 ...
随机推荐
- 使用ABAP代码创建S/4HANA里的Sales Order
下图是使用ABAP代码创建的S/4HANA的Sales Order的截图: 其中红色区域的值是我代码里硬编码的,而蓝色是函数SD_SALESDOCUMENT_CREATE自己创建的. 来看下代码: D ...
- IOS 数据加密总结(及MD5加密)
数据安全总结 1.网络数据加密1> 加密对象:隐私数据,比如密码.银行信息2> 加密方案* 提交隐私数据,必须用POST请求* 使用加密算法对隐私数据进行加密,比如MD53> 加密增 ...
- HashMap通过hashcode对其内容进行快速查找,而 TreeMap中所有的元素都保持着某种固定的顺序
HashMap通过hashcode对其内容进行快速查找,而 TreeMap中所有的元素都保持着某种固定的顺序,如果你需要得到一个有序的结果你就应该使用TreeMap(HashMap中元素的排列顺序是不 ...
- Uva 10820 交表
题目链接:https://uva.onlinejudge.org/external/108/10820.pdf 题意: 对于两个整数 x,y,输出一个函数f(x,y),有个选手想交表,但是,表太大,需 ...
- http协议的发展历史
在最早的时候,第一个定稿的http协议是http/0.9版本,在这个版本里面,http协议,它的内容,非常非常的简单 只有一个命令,就是GET 对应的就是我们现在经常用到的get请求,post请求,这 ...
- 深入理解MyBatis-Spring中间件(spring/mybatis整合)
转:http://blog.csdn.net/fqz_hacker/article/details/53485833 Mybatis-Spring 1.应用 mybatis是比较常用的数据库中间件,我 ...
- centos6 yum 安装 install c++4.8 gcc4.8
cd /etc/yum.repos.d wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo yum --enablerep ...
- Python类型转换+序列操作+基本概念辨析速查手册
第一部分是Python语言中基础中的基础,根据网上资料,合并如下: 1.类型转换 int(x [,base]) 将x转换为一个整数 long(x [,base]) 将x ...
- 树状数组区间修改and查询和
在差分数组上稍加改变,就可以实现这个骚操作 首先我们先来看一看普通的树状数组(基于差分)怎么暴力的求解区间和就是询问区间长度次和 \(\sum^{i=1}_{len}\sum^{j=1}_{i}bas ...
- Shell编程学习之Shell编程基础(一)
这篇随笔将要介绍关于Shell编程的基本知识,这些将会在假设你已经熟悉了Linux系统和命令行的基本知识. 构建基本脚本 你应该了解或熟悉使用Shell命令行了,但是只是使用Shell命令行的命令,有 ...