// wb_rebuild.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "rebuild_manager.h"

int main()
{
	RebuildManager *manager = new RebuildManager();
	if (!manager->Init())
	{
		printf("error : init failed ...\n");
		goto Error;
	}
	printf("init ok ...\n");

	if (!manager->ConnectMqttServer())
	{
		printf("error : connect mqtt failed ...\n");
		goto Error;
	}

	while (manager->Connected() == 0)
	{
		printf("wait connect mqtt resualt ...\n");

		std::chrono::milliseconds dura(1000);
		std::this_thread::sleep_for(dura);
	}
	if (manager->Connected() == 1)
	{
		printf("connect mqtt server success ...\n");
	}
	else
	{
		goto Error;
	}

	if (!manager->OpenMediaFile())
	{
		printf("error : open media file failed ...\n");
		goto Error;
	}

	manager->StartPull();

	while (!manager->EndOfFile())
	{
		std::chrono::milliseconds dura(1000);
		std::this_thread::sleep_for(dura);
	}

	manager->StopPull();
	manager->CloseMediaFile();
	manager->DisConnectMqttServer();

	printf("mission completed ...!");

Error:
	delete manager;

	printf("press enter key to exit ...\n");
	getchar();
	return 0;
}
