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尽可能多,任意 ...
随机推荐
- pat甲级1107
1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your ...
- POJ-3669 Meteor Shower---BFS+预处理
题目链接: https://vjudge.net/problem/POJ-3669 题目大意: 巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, ...
- 【BZOJ3506】[CQOI2014] 排序机械臂(Splay)
点此看题面 大致题意: 给你\(n\)个数.第一次找到最小值所在位置\(P_1\),翻转\([1,P_1]\),第二次找到剩余数中最小值所在位置\(P_2\),翻转\([2,P_2]\),以此类推.求 ...
- 关于 npm install 命令
使用 `npm install` 命令安装模块时 ,有以下几种形式: 安装模块到项目 node_modules 目录下,不会将模块依赖写入 dependencies 或 devDependencies ...
- python读取mat文件
一.mat文件 mat数据格式是Matlab的数据存储的标准格式.在Matlab中主要使用load()函数导入一个mat文件,使用save()函数保存一个mat文件.对于文件 load('data.m ...
- 安装juicer
由于我第一次安装 JUICER时遇到了很多问题,现在把这些问题都记录下来,给同样第一次安装使用的同学一点借鉴. 前面已经安装了Torch3和Tracter,这都是为安装Juicer做的准备,现在安装J ...
- 最大独立集问题-maximal independent set problem
原文链接 http://blog.csdn.net/xin_jmail/article/details/29597471 http://blog.csdn.net/xin_jmail/article/ ...
- 旧文备份:在CANopen网络中通过LSS服务设置节点地址和网络波特率
CANopen专有个子协议用来描述怎样去通过网络设置节点地址和波特率,就是CiA DSP-305,大伙都叫LSS协议,是Layer Setting Services的缩写,不太好翻译,可以叫底层设置服 ...
- loss 和accuracy的关系梳理
最近打算总结一下这部分东西,先记录留个脚印.
- 图解HTTP-1.web和网络基础
目录 1. 3 项 WWW 构建技术 2. TCP/IP 是互联网相关的各类协议族的总称 协议(protocol) TCP/IP分层管理 TCP/IP通信传输流 封装(encapsulate) 3. ...