从0开始Cmake工程系列
第一章 V1.0需求锁定
本系列文章会以章节来模拟项目进度,从而展现出一种成熟的软件开发流程,让同学们早日熟悉未来的工作环境。
文章目录
前言
参加工作之前,只是懂些学校里面的玩具程序,参加工作后才有了开发、集成、测试整套流程的概念,现在把流程以博客的形式记录下来,希望对同学们有所帮助。
工程本身会使用C++开发语言,测试,集成脚本会使用python,shell脚本,编译工具使用Cmake,编译器使用g++,运行环境为Ubuntu 18
软件需求大纲
玩家投币后游戏机开始工作,一个币可以玩100s,若玩家选择继续游戏就需要再次投币,如果玩家20s内不再投币就结束,下次投币将会从头开始。
1 软件基线
流程 | V1.0 | V1.1 | V1.2 | V2.0 | V3.0 | V3.1 | |||
---|---|---|---|---|---|---|---|---|---|
系统需求(大纲) | 9月11号 | ||||||||
软件需求锁定 | 9月12号 | ||||||||
内部软件发布 | 9月13号 | ||||||||
内部测试 | 9月16号 | ||||||||
系统测试(无) | NA | ||||||||
软件集成(无) | NA | ||||||||
正式发布 | 9月18号 | ||||||||
完成状态 | |||||||||
实现功能 | |||||||||
备注 |
2 项目管理
人员参与管理:
人员 | 分工 |
---|---|
读者 | 客户,Boss,用户 |
Alice | 产品兼任项目经理 |
Mike | 需求工程师 |
Lucy | 开发工程师 |
Tom | 测试工程师 |
Peter | 集成工程师 |
项目会议:
会议日期 | 内容 | 参与人 |
---|---|---|
9月12号 | V1.0软件释放及测试通气会 | 需求,开发,测试 |
人力资源分配:
需求请假3天
3 软件需求拆解
3.1 游戏机功能开发需求:
3.1.1 输入:
投币,玩家的操作,定义数据结构
3.1.2 输出:
游戏信息反馈,定义数据结构:
3.2 内部逻辑:
状态机
4 软件详细设计
4.1 架构设计
输入输出类:数据缓存结构,服务端,基于MQTT功能,对接游戏机类
游戏机类,封装处理输入输出以及状态机功能
定时器类,定时通知游戏机检查投币状况。
4.2 详细设计
游戏机类
#include <iostream>
#include "observer.hpp"
int main()
{
Observer observer;
observer.tranformer.Onlistern();
// #include <string>
// #include <memory>
// #include <string>
// #include <memory>
// #include <vector>
// #include <string>
// #include <cstdio>
// #include <thread>
// #include <iostream>
// using namespace std;
// struct z {
// z(int rhs) { cout << "zzz" << endl; };
// };
// #include <fstream>
// #include <stdio.h>
// #include <sys/statfs.h>
// #include <string.h>
// #include <dirent.h>
// #include <stdbool.h>
// #include <sys/stat.h>
// int file_size(char* filename)
// {
// int size = 0;
// struct stat sss;
// stat(filename,&sss);
// size = sss.st_size;
// return size;
// }
// int Udisk_Capacity(char *chardir,int *total,int *free)
// {
// struct statfs s;
// memset(&s, 0, sizeof(struct statfs));
// if( 0 != statfs(chardir, &s) )
// {
// return -1;
// }
// if(s.f_bsize >= 1024)
// {
// printf("\n if(s.f_bsize >= 1024)\n");
// *total = (int)( (s.f_bsize / 1024 ) * s.f_blocks );
// *free = (int) ( ( s.f_bsize / 1024 ) * s.f_bavail );
// }
// else
// {
// printf("\n if(s.f_bsize < 1024) else\n");
// *total = (int)( (s.f_blocks / 1024 ) * s.f_bsize );
// *free = (int) ( ( s.f_bavail / 1024 ) * s.f_bsize );
// }
// //zhao
// cout<<"磁盘的整体空间"<<(s.f_blocks * s.f_frsize)/1024/1024<<endl;
// cout<<(s.f_bfree * s.f_frsize)/1024/1024<<endl;
// cout<<(s.f_bavail * s.f_frsize)/1024/1024<<endl;
// }
// /*
// 磁盘的整体空间:(buf.f_blocks * buf.f_frsize)/1024/1024)MB
// 磁盘的空闲空间:(buf.f_bfree * buf.f_frsize)/1024/1024)MB
// 磁盘的用户级空闲空间:(buf.f_bavail * buf.f_frsize)/1024/1024)MB
// */
// int main()
// {
// //std::vector<std::thread> workers_;
// //int *y = new int(3);
// //std::shared_ptr<int> x(y);
// //std::cout << *x << endl;;
// //z* zz = new z(4500);
// //shared_ptr<z> p(zz);
// fstream file;
// // file.open("zhao.txt",ios::out);
// // file.write("zhao ", 4);
// // file.write("tong ", 4);
// file.open("xxx",ios::out);
// file.write("xxxx", 4);
// file.close();
// if(0 == remove("zhao.txt")){
// cout<<rename("xxx","zhao.txt")<<endl;
// }//如果没有成功删除临时log文件,就说明临时配置文件write后,因为空间不足,调用close没有flush到文件里,就保留原始配置文件
// else{
// cout<<"no space for ini"<<endl;
// }
// cout<<file_size("zhao.txt")<<endl;
// int a,b;
// Udisk_Capacity("/home/z/learn/strategymethod",&a,&b);
// cout<<a<<"====="<<b<<endl;
// return 0;
// }
// #include <iostream>
// #include <functional>
// using namespace std;
// void test(){cout<<"qqqq"<<endl;}
// class XX
// {
// public:
// void xx(){cout<<"iiiiii"<<endl;};
// };
// typedef void (XX::*tong)();
// void test2(tong vv,XX* hh){(hh->*vv)();}
// int main()
// {
// XX zhal;
// tong a1 = &XX::xx;
// (zhal.*a1)();
// std::function<void(tong aa,XX* bb)> yang;
// yang = test2;
// yang(&XX::xx,&zhal);
// // ZZ xu;
// // xu.name.*ZZ::yang()
// // (zhao->yang)();
// // &XX::xx;
// // test;
// // test();
// // cout<<XX::yy<<endl;
// // cout<<typeid(XX::yy).name()<<endl;
// // cout<<typeid(&XX::yy).name()<<endl;
// // // cout<<typeid(XX::xx).name()<<endl;
// // cout<<&XX::xx<<endl;
// // cout<<typeid(&XX::xx).name()<<endl;
// // // cout<<typeid(&XX::a).name()<<endl;
// // cout<<&test<<endl;
// // cout<<test<<endl;
// // cout<<typeid(test).name()<<endl;
// }
#include <iostream>
#include <functional>
#include <memory>
using namespace std;
shared_ptr<int> test(int &x)
{
cout<<"11110"<<endl;
shared_ptr<int> xx = make_shared<int>(33);
return xx;
}
int main()
{
function<shared_ptr<int>(int&)> zhao;
zhao = test;
int a=3;
auto it =zhao(a);
cout<<it.use_count()<<endl;
}
}
定时器类:
#include <iostream>
void Observer::onlistern(void* data,int size,int type)
{
printf("data:[%d]\n",*(int*)data);
filter.Onlistern();
}
输入输出容器:
#include <string>
#include <memory>
#include <string>
#include <memory>
#include <vector>
#include <string>
#include <cstdio>
#include <thread>
#include <iostream>
using namespace std;
struct z {
z(int rhs) { cout << "zzz" << endl; };
};
#include <fstream>
#include <stdio.h>
#include <sys/statfs.h>
#include <string.h>
#include <dirent.h>
#include <stdbool.h>
#include <sys/stat.h>
int file_size(char* filename)
{
int size = 0;
struct stat sss;
stat(filename,&sss);
size = sss.st_size;
return size;
}
int main()
{
//std::vector<std::thread> workers_;
//int *y = new int(3);
//std::shared_ptr<int> x(y);
//std::cout << *x << endl;;
//z* zz = new z(4500);
//shared_ptr<z> p(zz);
fstream file;
// file.open("zhao.txt",ios::out);
// file.write("zhao ", 4);
// file.write("tong ", 4);
file.open("xxx",ios::out);
file.write("xxxx", 4);
file.close();
if(0 == remove("zhao.txt")){
cout<<rename("xxx","zhao.txt")<<endl;
}//如果没有成功删除临时log文件,就说明临时配置文件write后,因为空间不足,调用close没有flush到文件里,就保留原始配置文件
else{
cout<<"no space for ini"<<endl;
}
cout<<file_size("zhao.txt")<<endl;
return 0;
}
5 软件集成及测试
编译使用Cmake工具,目录结构如下:
cmake_minimum_required (VERSION 3.5)
project(mainProject)
set(ROOT_PATH /home/z/learn/observer/)
include_directories(
${PROJECT_SOURCE_DIR}/../include/
${PROJECT_SOURCE_DIR}/observer/include/
${PROJECT_SOURCE_DIR}/observer/creator/include/
${PROJECT_SOURCE_DIR}/observer/transformer/include/
${PROJECT_SOURCE_DIR}/manager/include/
)
add_subdirectory(${PROJECT_SOURCE_DIR}/manager)
add_subdirectory(${PROJECT_SOURCE_DIR}/observer)
add_definitions(-Ddebug)
add_executable(main
main.cpp
)
target_link_libraries(main PRIVATE
observer
manager
)
install(TARGETS main RUNTIME DESTINATION ${ROOT_PATH}/bin/)
待续中。