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(); }

最新文章

  1. JavaScript之bind,call,apply
  2. thinkphp 查询当天 ,本周,本月,本季度,本年度,全部, 数据方法
  3. 160809212田京诚C语言程序设计实验2 选择结构程序设计_进阶
  4. css 实现三角形的原理
  5. INADDR_ANY的确切含义
  6. Linux—fork函数学习笔记
  7. Java:标示符 基本数据类型
  8. hdu 4508 湫湫系列故事——减肥记I(完全背包)
  9. php smarty insert用法
  10. 使用AsyncTask实现图片加载
  11. 【HTML+CSS】(1)基本语法
  12. STL中map用法
  13. eclipse开发创建web项目
  14. MySQL文档翻译(八)附英文原文---性能优化概览
  15. 9.Odoo产品分析 (二) – 商业板块(4) –讨论(1)
  16. Appium-两个小报错
  17. git拉取远程分支并创建本地分支
  18. innodb引擎对自增字段(auto_increment)的处理
  19. 如何使用tomcat,使用域名直接访问javaweb项目首页
  20. C#获取本地磁盘信息

热门文章

  1. Cholesky分解(Cholesky decomposition / Cholesky )
  2. [原创][Windows] Win7安装visual c++ 2015 redistributable x64失败
  3. ODBC驱动程序丢失解决方法
  4. 基于LBS的多人聊天
  5. Codeforces Round #347 (Div.2)_B. Rebus
  6. caffe的损失函数
  7. 3.Mysql集群------Mycat分库分表
  8. docker快速安装jenkins
  9. Centos7 使用LVM进行新加磁盘管理
  10. Cluster - HA -keepalived