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尽可能多,任意 ...
随机推荐
- python数组列表、字典、拷贝、字符串
python中字符串方法 name = "I teased at life as if it were a foolish game" print(name.capitalize( ...
- April 27 2017 Week 17 Thursday
Had I not seen the sun, I could have borne the shade. 我本可以忍受黑暗,如果我不曾见过阳光. A poem by Emily Dickinson, ...
- April 20 2017 Week 16 Thursday
We are all in the gutter, but some of us are looking at the stars. 我们都生活在阴沟里,但仍有人仰望星空. In the past m ...
- OpenCV视觉库
视频会议软件的视频质量除了与外置设备.编码器相关外,还与视频的后处理技术相关,视频图像通过后处理技术,如图像增强.图像去噪等,图像质量会得到主观上较大的提高.而我们通常的视频后处理技术会采用开源的项目 ...
- [pytorch] 官网教程+注释
pytorch官网教程+注释 Classifier import torch import torchvision import torchvision.transforms as transform ...
- CUDA 纹理内存
原文链接 1.概述 纹理存储器中的数据以一维.二维或者三维数组的形式存储在显存中,可以通过缓存加速访问,并且可以声明大小比常数存储器要大的多. 在kernel中访问纹理存储器的操作称为纹理拾取(tex ...
- extjs3EmptyText 上传自动清空的问题
在extjs3表单的操作中,输入框经常有提示性的默认字段,比如: // === 接入单位的Form表单 ====== var jrdwForm = new Ext.form.FormPanel({ b ...
- android 圆角图片的实现形式
android 圆角图片的实现形式,包括用第三方.也有系统的.比如makeramen:roundedimageview,系统的cardview , glide .fresco . compile 'c ...
- Centos防火墙添加IP白名单
Centos iptables防火墙添加IP白名单,指定IP可访问端口 vi /etc/sysconfig/iptables 以下为我虚拟机的防火墙为例(Centos 7) # sample conf ...
- js复习,预编译
注意:函数声明整体提升.变量 声明提升 1.imply global 暗示全局变量:即任何变量,如果变量未声明就赋值,此变量就为全局对象所有 ==> eg: a = 122;==> e ...