记录一个小白参加工作后的历程。从0开始学会构建CMake工程,按照V字开发模型编写一个有意义工程(加入了工程经常会用到的回调,称为观察者模式,并以连更的形式为同学展示未来的工作内容)

从0开始Cmake工程系列

第一章 V1.0需求锁定

本系列文章会以章节来模拟项目进度,从而展现出一种成熟的软件开发流程,让同学们早日熟悉未来的工作环境。



前言

参加工作之前,只是懂些学校里面的玩具程序,参加工作后才有了开发、集成、测试整套流程的概念,现在把流程以博客的形式记录下来,希望对同学们有所帮助。
工程本身会使用C++开发语言,测试,集成脚本会使用python,shell脚本,编译工具使用Cmake,编译器使用g++,运行环境为Ubuntu 18


软件需求大纲

玩家投币后游戏机开始工作,一个币可以玩100s,若玩家选择继续游戏就需要再次投币,如果玩家20s内不再投币就结束,下次投币将会从头开始。

1 软件基线

流程V1.0V1.1V1.2V2.0V3.0V3.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/)

待续中。

总结

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值