<commit_before>// Virvo - Virtual Reality Volume Rendering
// Copyright (C) 1999-2003 University of Stuttgart, 2004-2005 Brown University
// Contact: Jurgen P. Schulze, jschulze@ucsd.edu
//
// This file is part of Virvo.
//
// Virvo is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library (see license.txt); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#ifdef VV_DEBUG_MEMORY
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
#endif

#include "vvresourcemanager.h"
#include "vvsimpleserver.h"

#include <virvo/vvdebugmsg.h>
#include <virvo/vvrequestmanagement.h>
#include <virvo/vvremoteevents.h>
#include <virvo/vvremoteserver.h>
#include <virvo/vvsocketio.h>
#include <virvo/vvvoldesc.h>
#include <virvo/vvtcpsocket.h>

#include <iostream>
#include <pthread.h>

namespace
{
  struct ThreadArgs
  {
    vvTcpSocket *_sock;
  };
}

vvSimpleServer* vvSimpleServer::_instance = NULL;

vvSimpleServer::vvSimpleServer(bool useBonjour)
  : vvServer(useBonjour)
{
  _instance = this;
  if (_useBonjour)
  {
    registerToBonjour();
  }
}

vvSimpleServer::~vvSimpleServer()
{
  if(_useBonjour) unregisterFromBonjour();
}

bool vvSimpleServer::handleEvent(ThreadData *tData, virvo::RemoteEvent event, const vvSocketIO& io)
{
  switch (event)
  {
  case virvo::GpuInfo:
    {
      std::vector<vvGpu*> gpus = vvGpu::list();
      std::vector<vvGpu::vvGpuInfo> ginfos;
      for(std::vector<vvGpu*>::iterator gpu = gpus.begin(); gpu != gpus.end(); gpu++)
      {
        ginfos.push_back(vvGpu::getInfo(*gpu));
      }
      io.putGpuInfos(ginfos);
    }
    return true;
  case virvo::Disconnect:
    vvServer::handleEvent(tData, event, io);
    return false;
  default:
    return vvServer::handleEvent(tData, event, io);
  }
}

void vvSimpleServer::handleNextConnection(vvTcpSocket *sock)
{
  vvDebugMsg::msg(3, "vvSimpleServer::handleNextConnection()");

  ThreadArgs *args = new ThreadArgs;
  args->_sock = sock;

  pthread_t pthread;
  pthread_create(&pthread,  NULL, handleClientThread, args);
  pthread_detach(pthread);
}

void * vvSimpleServer::handleClientThread(void *param)
{
  vvDebugMsg::msg(3, "vvSimpleServer::handleClientThread()");

  ThreadData *tData = new ThreadData;
  ThreadArgs *args = reinterpret_cast<ThreadArgs*>(param);

  vvTcpSocket *sock = args->_sock;

  vvSocketIO io(sock);
  virvo::RemoteEvent event;
  while (io.getEvent(event) == vvSocket::VV_OK)
  {
    if (!_instance->handleEvent(tData, event, io))
    {
      break;
    }
  }
  _instance->handleEvent(tData, virvo::Disconnect, io);

  sock->disconnectFromHost();
  delete sock;
  delete args;
  delete tData;

  pthread_exit(NULL);
#ifdef _WIN32
  return NULL;
#endif
}

bool vvSimpleServer::registerToBonjour()
{
  vvDebugMsg::msg(3, "vvSimpleServer::registerToBonjour()");
  vvBonjourEntry entry = vvBonjourEntry("Virvo Server", "_vserver._tcp", "");
  return _registrar.registerService(entry, _port);
}

void vvSimpleServer::unregisterFromBonjour()
{
  vvDebugMsg::msg(3, "vvSimpleServer::unregisterFromBonjour()");
  _registrar.unregisterService();
}

bool vvSimpleServer::createRemoteServer(ThreadData* tData, vvTcpSocket* sock)
{
  vvDebugMsg::msg(3, "vvSimpleServer::createRemoteServer() Enter");

  tData->renderertype = tData->remoteServerType == vvRenderer::REMOTE_IMAGE
    ? "default"
    : "rayrend";

  return vvServer::createRemoteServer(tData, sock);
}

//===================================================================
// End of File
//===================================================================
// vim: sw=2:expandtab:softtabstop=2:ts=2:cino=\:0g0t0
<commit_msg>Use rayrendcuda for image-based remote rendering<commit_after>// Virvo - Virtual Reality Volume Rendering
// Copyright (C) 1999-2003 University of Stuttgart, 2004-2005 Brown University
// Contact: Jurgen P. Schulze, jschulze@ucsd.edu
//
// This file is part of Virvo.
//
// Virvo is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library (see license.txt); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#ifdef VV_DEBUG_MEMORY
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
#endif

#include "vvresourcemanager.h"
#include "vvsimpleserver.h"

#include <virvo/vvdebugmsg.h>
#include <virvo/vvrequestmanagement.h>
#include <virvo/vvremoteevents.h>
#include <virvo/vvremoteserver.h>
#include <virvo/vvsocketio.h>
#include <virvo/vvvoldesc.h>
#include <virvo/vvtcpsocket.h>

#include <iostream>
#include <pthread.h>

namespace
{
  struct ThreadArgs
  {
    vvTcpSocket *_sock;
  };
}

vvSimpleServer* vvSimpleServer::_instance = NULL;

vvSimpleServer::vvSimpleServer(bool useBonjour)
  : vvServer(useBonjour)
{
  _instance = this;
  if (_useBonjour)
  {
    registerToBonjour();
  }
}

vvSimpleServer::~vvSimpleServer()
{
  if(_useBonjour) unregisterFromBonjour();
}

bool vvSimpleServer::handleEvent(ThreadData *tData, virvo::RemoteEvent event, const vvSocketIO& io)
{
  switch (event)
  {
  case virvo::GpuInfo:
    {
      std::vector<vvGpu*> gpus = vvGpu::list();
      std::vector<vvGpu::vvGpuInfo> ginfos;
      for(std::vector<vvGpu*>::iterator gpu = gpus.begin(); gpu != gpus.end(); gpu++)
      {
        ginfos.push_back(vvGpu::getInfo(*gpu));
      }
      io.putGpuInfos(ginfos);
    }
    return true;
  case virvo::Disconnect:
    vvServer::handleEvent(tData, event, io);
    return false;
  default:
    return vvServer::handleEvent(tData, event, io);
  }
}

void vvSimpleServer::handleNextConnection(vvTcpSocket *sock)
{
  vvDebugMsg::msg(3, "vvSimpleServer::handleNextConnection()");

  ThreadArgs *args = new ThreadArgs;
  args->_sock = sock;

  pthread_t pthread;
  pthread_create(&pthread,  NULL, handleClientThread, args);
  pthread_detach(pthread);
}

void * vvSimpleServer::handleClientThread(void *param)
{
  vvDebugMsg::msg(3, "vvSimpleServer::handleClientThread()");

  ThreadData *tData = new ThreadData;
  ThreadArgs *args = reinterpret_cast<ThreadArgs*>(param);

  vvTcpSocket *sock = args->_sock;

  vvSocketIO io(sock);
  virvo::RemoteEvent event;
  while (io.getEvent(event) == vvSocket::VV_OK)
  {
    if (!_instance->handleEvent(tData, event, io))
    {
      break;
    }
  }
  _instance->handleEvent(tData, virvo::Disconnect, io);

  sock->disconnectFromHost();
  delete sock;
  delete args;
  delete tData;

  pthread_exit(NULL);
#ifdef _WIN32
  return NULL;
#endif
}

bool vvSimpleServer::registerToBonjour()
{
  vvDebugMsg::msg(3, "vvSimpleServer::registerToBonjour()");
  vvBonjourEntry entry = vvBonjourEntry("Virvo Server", "_vserver._tcp", "");
  return _registrar.registerService(entry, _port);
}

void vvSimpleServer::unregisterFromBonjour()
{
  vvDebugMsg::msg(3, "vvSimpleServer::unregisterFromBonjour()");
  _registrar.unregisterService();
}

bool vvSimpleServer::createRemoteServer(ThreadData* tData, vvTcpSocket* sock)
{
  vvDebugMsg::msg(3, "vvSimpleServer::createRemoteServer() Enter");

  tData->renderertype = tData->remoteServerType == vvRenderer::REMOTE_IMAGE
    ? "default"
    : "rayrendcuda";

  return vvServer::createRemoteServer(tData, sock);
}

//===================================================================
// End of File
//===================================================================
// vim: sw=2:expandtab:softtabstop=2:ts=2:cino=\:0g0t0
<|endoftext|>


<commit_before>#include <TitleScene.hpp>

using namespace uth;

uth::Layer& TitleScene::getLayer(LayerId id)
{
	return *m_layers[id];
}
TitleScene::TitleScene()
{
	m_BGM = uthRS.LoadSound("Audio/Music/menu_theme.wav");
	m_BGM->Play();

	auto& window = uthEngine.GetWindow();

	getLayer(LayerId::TitleBackground);
	getLayer(LayerId::Buttons);

	for (auto& e : m_layers)
	{
		AddChild(e.second = new Layer());
	}

	auto TitleBgTex = uthRS.LoadTexture("Title/menu_bg.png");
	TitleBgTex->SetSmooth(true);
	getLayer(LayerId::TitleBackground).AddChild(m_TitleBG = new GameObject());
	m_TitleBG->AddComponent(new Sprite(TitleBgTex,"TitleBG"));
	m_TitleBG->transform.SetOrigin(uth::Origin::TopLeft);
	m_TitleBG->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2,
	window.GetCamera().GetPosition().y - window.GetSize().y / 2);

	//play-button

	uth::Texture* PlayTex = uthRS.LoadTexture("Title/Play.png");
	PlayTex->SetSmooth(true);
	getLayer(LayerId::Buttons).AddChild(m_PlayB = new GameObject());
	m_PlayB->AddComponent(new AnimatedSprite(PlayTex,2,2,1,0));
	m_PlayB->transform.SetOrigin(uth::Origin::TopLeft);
	m_PlayB->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2 + 150,
		window.GetCamera().GetPosition().y - window.GetSize().y / 2 + 400);
	button = new Button(m_PlayB);

	//credits
	getLayer(LayerId::Buttons).AddChild(m_CreditsB = new GameObject());
	uth::Texture* CredTex = uthRS.LoadTexture("Title/credits.png");
	CredTex->SetSmooth(true);
	m_CreditsB->AddComponent(new AnimatedSprite(CredTex, 2, 2, 1, 0));
	m_CreditsB->transform.SetOrigin(uth::Origin::TopLeft);
	m_CreditsB->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2 + 175,
		window.GetCamera().GetPosition().y - window.GetSize().y / 2 + 550);
	button2 = new Button(m_CreditsB);

	//options (ball)
	getLayer(LayerId::Buttons).AddChild(m_OptionsB = new GameObject());
	uth::Texture* OptionsTex = uthRS.LoadTexture("Title/options.png");
	OptionsTex->SetSmooth(true);
	m_OptionsB->AddComponent(new AnimatedSprite(OptionsTex, 2, 2, 1, 0));
	m_OptionsB->transform.SetOrigin(uth::Origin::TopLeft);
	m_OptionsB->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2 + 630 ,
		window.GetCamera().GetPosition().y - window.GetSize().y / 2 + 600);
	button3 = new Button(m_OptionsB);

	getLayer(LayerId::Buttons).AddChild(m_CBG = new GameObject());
	uth::Texture* CBGTex = uthRS.LoadTexture("UI/pause_BG.png");
	CBGTex->SetSmooth(true);
	m_CBG->AddComponent(new Sprite(CBGTex, "CBG"));
	m_CBG->transform.SetOrigin(uth::Origin::TopLeft);
	m_CBG->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
		uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);

	getLayer(LayerId::Buttons).AddChild(m_EscB = new GameObject());
	uth::Texture* EscTex = uthRS.LoadTexture("UI/esc.png");
	OptionsTex->SetSmooth(true);
	m_EscB->AddComponent(new AnimatedSprite(EscTex, 2, 2, 1, 0));
	m_EscB->transform.SetOrigin(uth::Origin::TopLeft);
	m_EscB->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
		uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);
	button4 = new Button(m_EscB);

}
TitleScene::~TitleScene()
{}
void TitleScene::Update(float dt)
{

	if (!Creditsu)
	{
		button->update(dt);
		button2->update(dt);
		button3->update(dt);
		m_CBG->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);

		m_EscB->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);

		if (button->IsPressedS() )
		{
			uthSceneM.GoToScene(0);
			m_BGM->Stop();
		}

		if (button2->IsPressedS() )
		{
			Creditsu = true;
		}

	}
	else
	{
		m_EscB->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 + 1150 ,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 +75);

		m_CBG->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 + 780,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 + 50);
		button4->update(dt);

		if (button4->IsPressedS())
		{
			Creditsu = false;
		}

	}
}

bool TitleScene::Init()
{
	return true;
}
bool TitleScene::DeInit()
{
	return true;
}

<commit_msg>+edits<commit_after>#include <TitleScene.hpp>

using namespace uth;

uth::Layer& TitleScene::getLayer(LayerId id)
{
	return *m_layers[id];
}
TitleScene::TitleScene()
{
	m_BGM = uthRS.LoadSound("Audio/Music/menu_theme.wav");
	m_BGM->Play();

	auto& window = uthEngine.GetWindow();

	getLayer(LayerId::TitleBackground);
	getLayer(LayerId::Buttons);

	for (auto& e : m_layers)
	{
		AddChild(e.second = new Layer());
	}

	auto TitleBgTex = uthRS.LoadTexture("Title/menu_bg.png");
	TitleBgTex->SetSmooth(true);
	getLayer(LayerId::TitleBackground).AddChild(m_TitleBG = new GameObject());
	m_TitleBG->AddComponent(new Sprite(TitleBgTex,"TitleBG"));
	m_TitleBG->transform.SetOrigin(uth::Origin::TopLeft);
	m_TitleBG->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2,
	window.GetCamera().GetPosition().y - window.GetSize().y / 2);

	//play-button

	uth::Texture* PlayTex = uthRS.LoadTexture("Title/Play.png");
	PlayTex->SetSmooth(true);
	getLayer(LayerId::Buttons).AddChild(m_PlayB = new GameObject());
	m_PlayB->AddComponent(new AnimatedSprite(PlayTex,2,2,1,0));
	m_PlayB->transform.SetOrigin(uth::Origin::TopLeft);
	m_PlayB->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2 + 150,
		window.GetCamera().GetPosition().y - window.GetSize().y / 2 + 400);
	button = new Button(m_PlayB);

	//credits
	getLayer(LayerId::Buttons).AddChild(m_CreditsB = new GameObject());
	uth::Texture* CredTex = uthRS.LoadTexture("Title/credits.png");
	CredTex->SetSmooth(true);
	m_CreditsB->AddComponent(new AnimatedSprite(CredTex, 2, 2, 1, 0));
	m_CreditsB->transform.SetOrigin(uth::Origin::TopLeft);
	m_CreditsB->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2 + 175,
		window.GetCamera().GetPosition().y - window.GetSize().y / 2 + 550);
	button2 = new Button(m_CreditsB);

	//options (ball)
	getLayer(LayerId::Buttons).AddChild(m_OptionsB = new GameObject());
	uth::Texture* OptionsTex = uthRS.LoadTexture("Title/options.png");
	OptionsTex->SetSmooth(true);
	m_OptionsB->AddComponent(new AnimatedSprite(OptionsTex, 2, 2, 1, 0));
	m_OptionsB->transform.SetOrigin(uth::Origin::TopLeft);
	m_OptionsB->transform.SetPosition(window.GetCamera().GetPosition().x - window.GetSize().x / 2 + 630 ,
		window.GetCamera().GetPosition().y - window.GetSize().y / 2 + 600);
	button3 = new Button(m_OptionsB);

	getLayer(LayerId::Buttons).AddChild(m_CBG = new GameObject());
	uth::Texture* CBGTex = uthRS.LoadTexture("UI/pause_BG.png");
	CBGTex->SetSmooth(true);
	m_CBG->AddComponent(new Sprite(CBGTex, "CBG"));
	m_CBG->transform.SetOrigin(uth::Origin::TopLeft);
	m_CBG->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
		uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);

	getLayer(LayerId::Buttons).AddChild(m_EscB = new GameObject());
	uth::Texture* EscTex = uthRS.LoadTexture("UI/esc.png");
	OptionsTex->SetSmooth(true);
	m_EscB->AddComponent(new AnimatedSprite(EscTex, 2, 2, 1, 0));
	m_EscB->transform.SetOrigin(uth::Origin::TopLeft);
	m_EscB->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
		uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);
	button4 = new Button(m_EscB);

}
TitleScene::~TitleScene()
{}
void TitleScene::Update(float dt)
{

	if (!Creditsu)
	{
		button->update(dt);
		button2->update(dt);
		button3->update(dt);
		m_CBG->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);

		m_EscB->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 - 1000,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 - 1000);

		if (button->IsPressedS() )
		{
			uthSceneM.GoToScene(0);
			m_BGM->Stop();
		}

		if (button2->IsPressedS() )
		{
			Creditsu = true;
		}

	}
	else
	{
		m_EscB->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 + 1150 ,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 +75);

		m_CBG->transform.SetPosition(uthEngine.GetWindow().GetCamera().GetPosition().x - uthEngine.GetWindow().GetSize().x / 2 + 780,
			uthEngine.GetWindow().GetCamera().GetPosition().y - uthEngine.GetWindow().GetSize().y / 2 + 50);
		button4->update(dt);

		if (button4->IsPressedS())
		{
			Creditsu = false;
		}

	}
}

bool TitleScene::Init()
{
	return true;
}
bool TitleScene::DeInit()
{
	m_BGM = nullptr;
	return true;
}

<|endoftext|>


<commit_before>#include <psp2/ctrl.h>
#include <psp2/touch.h>
#include <psp2/moduleinfo.h>
#include <psp2/kernel/processmgr.h>

#include <string>
#include <cstdio>
#include <vita2d.h>

#include "../vitamenulib/libvitamenu/menu_manager.h"
#include "../vitamenulib/libvitamenu/menu.h"
#include "../vitamenulib/libvitamenu/menu_item.h"
#include "../vitamenulib/libvitamenu/utils.h"

#include "libUVL/libuvl.h"

PSP2_MODULE_INFO(0, 0, "kmenu");

void log(std::string s)
{
	printf("%s%s", s.c_str(), "\n");
}

void load_helloworld()
{
	char test_homebrew_file[] = "cache0:/VitaDefilerClient/Documents/helloworld.elf";

	if(uvl_load(&test_homebrew_file[0]) < 0)
	{
		log("Hello world failed to load!");
	}
	else
	{
		log("Hello world loaded!");
	}
}

int main() {
	log("Starting");
	vita2d_init();

	char menu_name[] = "kMenu";
	char test_menuitem_name[] = "Run a test";

	char background_file[] = "cache0:/VitaDefilerClient/Documents/splash.png";

  	MenuManager * manager = new MenuManager();

	Menu * menu = new Menu(manager, 100, 50);
	menu->setName(&menu_name[0]);
	menu->setBackground(&background_file[0]);
	menu->addMenuItem(new MenuItem(&test_menuitem_name[0], 100, 100, &load_helloworld));

	//input for both touch and joysticks
	SceCtrlData pad;
	SceTouchData touch;

	while(1) {
		//read input
		sceCtrlPeekBufferPositive(0, &pad, 1);
		sceTouchPeek(0, &touch, 1);

		//quit when you press triangle
		if (pad.buttons & PSP2_CTRL_TRIANGLE)
		{
			break;
		}

		manager->handleDpad(&pad);

		manager->handleTouch(&touch);

		vita2d_start_drawing();
		vita2d_clear_screen();

		manager->draw();

		vita2d_end_drawing();
		vita2d_swap_buffers();
	}

	log("Stopped.\n");

	vita2d_fini();

	sceKernelExitProcess(0);
	delete manager;

	return 0;
}<commit_msg>libUVL is C while rest of the program is c++<commit_after>#include <psp2/ctrl.h>
#include <psp2/touch.h>
#include <psp2/moduleinfo.h>
#include <psp2/kernel/processmgr.h>

#include <string>
#include <cstdio>
#include <vita2d.h>

#include "../vitamenulib/libvitamenu/menu_manager.h"
#include "../vitamenulib/libvitamenu/menu.h"
#include "../vitamenulib/libvitamenu/menu_item.h"
#include "../vitamenulib/libvitamenu/utils.h"

extern "C" {
	#include "libUVL/libuvl.h"
}

PSP2_MODULE_INFO(0, 0, "kmenu");

void log(std::string s)
{
	printf("%s%s", s.c_str(), "\n");
}

void load_helloworld()
{
	char test_homebrew_file[] = "cache0:/VitaDefilerClient/Documents/helloworld.elf";

	if(uvl_load(&test_homebrew_file[0]) < 0)
	{
		log("Hello world failed to load!");
	}
	else
	{
		log("Hello world loaded!");
	}
}

int main() {
	log("Starting");
	vita2d_init();

	char menu_name[] = "kMenu";
	char test_menuitem_name[] = "Run a test";

	char background_file[] = "cache0:/VitaDefilerClient/Documents/splash.png";

  	MenuManager * manager = new MenuManager();

	Menu * menu = new Menu(manager, 100, 50);
	menu->setName(&menu_name[0]);
	menu->setBackground(&background_file[0]);
	menu->addMenuItem(new MenuItem(&test_menuitem_name[0], 100, 100, &load_helloworld));

	//input for both touch and joysticks
	SceCtrlData pad;
	SceTouchData touch;

	while(1) {
		//read input
		sceCtrlPeekBufferPositive(0, &pad, 1);
		sceTouchPeek(0, &touch, 1);

		//quit when you press triangle
		if (pad.buttons & PSP2_CTRL_TRIANGLE)
		{
			break;
		}

		manager->handleDpad(&pad);

		manager->handleTouch(&touch);

		vita2d_start_drawing();
		vita2d_clear_screen();

		manager->draw();

		vita2d_end_drawing();
		vita2d_swap_buffers();
	}

	log("Stopped.\n");

	vita2d_fini();

	sceKernelExitProcess(0);
	delete manager;

	return 0;
}<|endoftext|>


<commit_before>#include "Daemon.hpp"

#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <fcntl.h>           /* For O_* constants */
#include <sys/stat.h>        /* For mode constants */
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include "Debug.hpp"

#if defined _DEBUG
extern TraceType currentTrace;
#endif

#define APPLICATION_INSTANCE_MUTEX_NAME "/tmp/animeDb_sem_on"

int SingleInstance::semid = -1;

__attribute__((constructor)) void on_start() {

	__builtin_puts("constructor");
	DaemonContainer::attachSem();
	//SingleInstance::__sem_instance = sem_open(APPLICATION_INSTANCE_MUTEX_NAME, O_CREAT | O_EXCL);
}

__attribute__((destructor)) void on_exit() {

	__builtin_puts("destructor");
	DaemonContainer::detachSem();
}

DaemonContainer::DaemonContainer():sid(0) {

	DaemonContainer::detachSem();
	pid = fork();
}

DaemonContainer::~DaemonContainer() {

}

bool DaemonContainer::initDaemon() {

	if (pid == 0) {

		umask(0);
		sid = setsid();

		if (sid > 0) {
			close(STDIN_FILENO);
			close(STDOUT_FILENO);
			close(STDERR_FILENO);
#if defined _DEBUG
			currentTrace = DAEMON;
#endif
			on_start();
			return true;
		}
	}
	return false;
}

bool DaemonContainer::isParentProcess() {

	 return pid > 0;
}

void DaemonContainer::detachSem()
{
	if (SingleInstance::isFirstRunning()) {

		semctl(SingleInstance::semid, 0, IPC_RMID);
		SingleInstance::semid = -1;
	}
}

void DaemonContainer::attachSem()
{
	key_t key = ftok(APPLICATION_INSTANCE_MUTEX_NAME, 'J');

	if (key != -1) {

		SingleInstance::semid = semget(key, 1, IPC_CREAT | IPC_EXCL);
	}
}

void DaemonContainer::startLoop(bool(*runMethod)(void)) {

	while((runMethod())){}
}

<commit_msg>add more debug<commit_after>#include "Daemon.hpp"

#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <fcntl.h>           /* For O_* constants */
#include <sys/stat.h>        /* For mode constants */
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include "Debug.hpp"

#if defined _DEBUG
extern TraceType currentTrace;
#endif

#define APPLICATION_INSTANCE_MUTEX_NAME "/tmp/animeDb_sem_on"

int SingleInstance::semid = -1;

__attribute__((constructor)) void on_start() {

	__builtin_puts("constructor");
	DaemonContainer::attachSem();
	//SingleInstance::__sem_instance = sem_open(APPLICATION_INSTANCE_MUTEX_NAME, O_CREAT | O_EXCL);
}

__attribute__((destructor)) void on_exit() {

	__builtin_puts("destructor");
	DaemonContainer::detachSem();
}

DaemonContainer::DaemonContainer():sid(0) {

	DaemonContainer::detachSem();
	pid = fork();
}

DaemonContainer::~DaemonContainer() {

}

bool DaemonContainer::initDaemon() {

	if (pid == 0) {

		umask(0);
		sid = setsid();

		if (sid > 0) {
			close(STDIN_FILENO);
			close(STDOUT_FILENO);
			close(STDERR_FILENO);
#if defined _DEBUG
			currentTrace = DAEMON;
#endif
			on_start();
			return true;
		}
	}
	return false;
}

bool DaemonContainer::isParentProcess() {

	 return pid > 0;
}

void DaemonContainer::detachSem()
{
	if (SingleInstance::isFirstRunning()) {

		semctl(SingleInstance::semid, 0, IPC_RMID);
		SingleInstance::semid = -1;
	}
}

void DaemonContainer::attachSem()
{
	key_t key = ftok(APPLICATION_INSTANCE_MUTEX_NAME, 'J');

	if (key != -1) {

		__builtin_puts("attachSem");
		SingleInstance::semid = semget(key, 1, IPC_CREAT | IPC_EXCL | 0666);
		if (!SingleInstance::isFirstRunning())
		{
			__builtin_puts("attach failed");
		}
	}
}

void DaemonContainer::startLoop(bool(*runMethod)(void)) {

	while((runMethod())){}
}

<|endoftext|>


<commit_before><commit_msg>fix: can call free after allocator_monitor destruction.<commit_after><|endoftext|>


<commit_before>/******************************************************************************
 * BRICS_3D - 3D Perception and Modeling Library
 * Copyright (c) 2014, KU Leuven
 *
 * Author: Sebastian Blumenthal
 *
 *
 * This software is published under a dual-license: GNU Lesser General Public
 * License LGPL 2.1 and Modified BSD license. The dual-license implies that
 * users of this code may choose which terms they prefer.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License LGPL and the BSD license for
 * more details.
 *
 ******************************************************************************/

#include "HDF5UpdateSerializer.h"
#include <fstream>

namespace brics_3d {
namespace rsg {

HDF5UpdateSerializer::HDF5UpdateSerializer(IOutputPort* port) :
		port(port) {

	/* some default values */
	storeMessageBackupsOnFileSystem = false;
	fileImageIncremet = 1*sizeof(char);

}

HDF5UpdateSerializer::~HDF5UpdateSerializer() {

}

bool HDF5UpdateSerializer::addNode(Id parentId, Id& assignedId,
		vector<Attribute> attributes, bool forcedId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::addGroup(Id parentId, Id& assignedId,
		vector<Attribute> attributes, bool forcedId) {
	LOG(DEBUG) << "HDF5UpdateSerializer: adding a Group-" << assignedId.toString();
	try {
		std::string fileName = "Group-" + assignedId.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::ADD, scene);
		HDF5Typecaster::addNodeIdToHDF5Group(parentId, scene, rsgParentIdName);

		H5::Group group = scene.createGroup("Group-" + assignedId.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::GROUP, group);
		HDF5Typecaster::addNodeIdToHDF5Group(assignedId, group);
		HDF5Typecaster::addAttributesToHDF5Group(attributes, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer addGroup: Cannot create a HDF serialization.";
		return false;
	}

	return true;
}

bool HDF5UpdateSerializer::addTransformNode(Id parentId,
		Id& assignedId, vector<Attribute> attributes,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		TimeStamp timeStamp, bool forcedId) {

	LOG(DEBUG) << "HDF5UpdateSerializer: adding a Transform-" << assignedId.toString();
	try {
		std::string fileName = "Transform-" + assignedId.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::ADD, scene);
		HDF5Typecaster::addNodeIdToHDF5Group(parentId, scene, rsgParentIdName);

		H5::Group group = scene.createGroup("Transform-" + assignedId.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::TRANSFORM, group);
		HDF5Typecaster::addNodeIdToHDF5Group(assignedId, group);
		HDF5Typecaster::addAttributesToHDF5Group(attributes, group);
		HDF5Typecaster::addTransformToHDF5Group(transform, timeStamp, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer addTransformNode: Cannot create a HDF serialization.";
		return false;
	}
	return true;
}

bool HDF5UpdateSerializer::addUncertainTransformNode(Id parentId,
		Id& assignedId, vector<Attribute> attributes,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		ITransformUncertainty::ITransformUncertaintyPtr uncertainty,
		TimeStamp timeStamp, bool forcedId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::addGeometricNode(Id parentId,
		Id& assignedId, vector<Attribute> attributes, Shape::ShapePtr shape,
		TimeStamp timeStamp, bool forcedId) {

	LOG(DEBUG) << "HDF5UpdateSerializer: adding a GeometricNode-" << assignedId.toString();
	try {
		std::string fileName = "GeometricNode-" + assignedId.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::ADD, scene);
		HDF5Typecaster::addNodeIdToHDF5Group(parentId, scene, rsgParentIdName);

		H5::Group group = scene.createGroup("GeometricNode-" + assignedId.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::GEOMETIRC_NODE, group);
		HDF5Typecaster::addNodeIdToHDF5Group(assignedId, group);
		HDF5Typecaster::addAttributesToHDF5Group(attributes, group);
		HDF5Typecaster::addShapeToHDF5Group(shape, group);
		HDF5Typecaster::addTimeStampToHDF5Group(timeStamp, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer addTransformNode: Cannot create a HDF serialization.";
		return false;
	}
	return true;
}

bool HDF5UpdateSerializer::setNodeAttributes(Id id,
		vector<Attribute> newAttributes) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::setTransform(Id id,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		TimeStamp timeStamp) {

	LOG(DEBUG) << "HDF5UpdateSerializer: updating a Transform-" << id.toString();
	try {
		std::string fileName = "Transform-Update-" + id.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::SET_TRANSFORM, scene);

		H5::Group group = scene.createGroup("Transform-Update-" + id.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::TRANSFORM, group);
		HDF5Typecaster::addNodeIdToHDF5Group(id, group);
		HDF5Typecaster::addTransformToHDF5Group(transform, timeStamp, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer setTransform: Cannot create a HDF serialization.";
		return false;
	}

	return true;
}

bool HDF5UpdateSerializer::setUncertainTransform(Id id,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		ITransformUncertainty::ITransformUncertaintyPtr uncertainty,
		TimeStamp timeStamp) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::deleteNode(Id id) {
	LOG(DEBUG) << "HDF5UpdateSerializer: deleting Node-" << id.toString();
	try {
		std::string fileName = "Node-Deletion-" + id.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::DELETE, scene);

		H5::Group group = scene.createGroup("Node-" + id.toString()); // The actual data
		HDF5Typecaster::addNodeIdToHDF5Group(id, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer setTransform: Cannot create a HDF serialization.";
		return false;
	}

	return true;
}

bool HDF5UpdateSerializer::addParent(Id id, Id parentId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::removeParent(Id id, Id parentId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::doSendMessage(std::string messageName) {
	std::ifstream inputFile;
	inputFile.open(messageName.c_str(), std::ios::binary);

	if(!inputFile.is_open()) {
		LOG(ERROR) << "Cannot open file" << messageName <<". Aborting.";
		return false;
	}

	/* get length of file */
	inputFile.seekg (0, std::ios::end);
	long length = inputFile.tellg();
	inputFile.seekg (0, std::ios::beg);
	LOG(DEBUG) << "HDF5UpdateSerializer: Sending message " << messageName << " with length " << length;

	char *buffer = new char [length];
	inputFile.read (buffer,length); // a single bunch of data is feed into the buffer
	inputFile.close();
	LOG(DEBUG) << "HDF5UpdateSerializer: prepared byte stream.";

	int transferredBytes;
	int returnValue =  port->write(buffer, length, transferredBytes);
	LOG(DEBUG) << "HDF5UpdateSerializer: \t" << transferredBytes << " bytes transferred.";

	delete buffer;
	return true;
}

bool HDF5UpdateSerializer::doSendMessage(H5::H5File message) {
	ssize_t fileSize = -1;
	ssize_t numberOfBytesRead;

//	fileSize = message.getFileSize();
    fileSize = H5Fget_file_image(message.getId(), NULL, 0);
	LOG(DEBUG) << "HDF5UpdateSerializer (VFD): Sending message with length " << fileSize;

	char *buffer = new char [fileSize];
    H5Fget_file_image(message.getId(), buffer, fileSize);
	LOG(DEBUG) << "HDF5UpdateSerializer (VFD): prepared byte stream with length " << numberOfBytesRead;

	int transferredBytes;
	int returnValue =  port->write(buffer, numberOfBytesRead, transferredBytes);
	LOG(DEBUG) << "HDF5UpdateSerializer (VFD): \t" << transferredBytes << " bytes transferred.";

	delete buffer;
	return true;
}

} /* namespace rsg */
} /* namespace brics_3d */
/* EOF */
<commit_msg>Bugfix for wrong buffer size in HDF5 serializer.<commit_after>/******************************************************************************
 * BRICS_3D - 3D Perception and Modeling Library
 * Copyright (c) 2014, KU Leuven
 *
 * Author: Sebastian Blumenthal
 *
 *
 * This software is published under a dual-license: GNU Lesser General Public
 * License LGPL 2.1 and Modified BSD license. The dual-license implies that
 * users of this code may choose which terms they prefer.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License LGPL and the BSD license for
 * more details.
 *
 ******************************************************************************/

#include "HDF5UpdateSerializer.h"
#include <fstream>

namespace brics_3d {
namespace rsg {

HDF5UpdateSerializer::HDF5UpdateSerializer(IOutputPort* port) :
		port(port) {

	/* some default values */
	storeMessageBackupsOnFileSystem = false;
	fileImageIncremet = 1*sizeof(char);

}

HDF5UpdateSerializer::~HDF5UpdateSerializer() {

}

bool HDF5UpdateSerializer::addNode(Id parentId, Id& assignedId,
		vector<Attribute> attributes, bool forcedId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::addGroup(Id parentId, Id& assignedId,
		vector<Attribute> attributes, bool forcedId) {
	LOG(DEBUG) << "HDF5UpdateSerializer: adding a Group-" << assignedId.toString();
	try {
		std::string fileName = "Group-" + assignedId.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::ADD, scene);
		HDF5Typecaster::addNodeIdToHDF5Group(parentId, scene, rsgParentIdName);

		H5::Group group = scene.createGroup("Group-" + assignedId.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::GROUP, group);
		HDF5Typecaster::addNodeIdToHDF5Group(assignedId, group);
		HDF5Typecaster::addAttributesToHDF5Group(attributes, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer addGroup: Cannot create a HDF serialization.";
		return false;
	}

	return true;
}

bool HDF5UpdateSerializer::addTransformNode(Id parentId,
		Id& assignedId, vector<Attribute> attributes,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		TimeStamp timeStamp, bool forcedId) {

	LOG(DEBUG) << "HDF5UpdateSerializer: adding a Transform-" << assignedId.toString();
	try {
		std::string fileName = "Transform-" + assignedId.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::ADD, scene);
		HDF5Typecaster::addNodeIdToHDF5Group(parentId, scene, rsgParentIdName);

		H5::Group group = scene.createGroup("Transform-" + assignedId.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::TRANSFORM, group);
		HDF5Typecaster::addNodeIdToHDF5Group(assignedId, group);
		HDF5Typecaster::addAttributesToHDF5Group(attributes, group);
		HDF5Typecaster::addTransformToHDF5Group(transform, timeStamp, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer addTransformNode: Cannot create a HDF serialization.";
		return false;
	}
	return true;
}

bool HDF5UpdateSerializer::addUncertainTransformNode(Id parentId,
		Id& assignedId, vector<Attribute> attributes,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		ITransformUncertainty::ITransformUncertaintyPtr uncertainty,
		TimeStamp timeStamp, bool forcedId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::addGeometricNode(Id parentId,
		Id& assignedId, vector<Attribute> attributes, Shape::ShapePtr shape,
		TimeStamp timeStamp, bool forcedId) {

	LOG(DEBUG) << "HDF5UpdateSerializer: adding a GeometricNode-" << assignedId.toString();
	try {
		std::string fileName = "GeometricNode-" + assignedId.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::ADD, scene);
		HDF5Typecaster::addNodeIdToHDF5Group(parentId, scene, rsgParentIdName);

		H5::Group group = scene.createGroup("GeometricNode-" + assignedId.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::GEOMETIRC_NODE, group);
		HDF5Typecaster::addNodeIdToHDF5Group(assignedId, group);
		HDF5Typecaster::addAttributesToHDF5Group(attributes, group);
		HDF5Typecaster::addShapeToHDF5Group(shape, group);
		HDF5Typecaster::addTimeStampToHDF5Group(timeStamp, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer addTransformNode: Cannot create a HDF serialization.";
		return false;
	}
	return true;
}

bool HDF5UpdateSerializer::setNodeAttributes(Id id,
		vector<Attribute> newAttributes) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::setTransform(Id id,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		TimeStamp timeStamp) {

	LOG(DEBUG) << "HDF5UpdateSerializer: updating a Transform-" << id.toString();
	try {
		std::string fileName = "Transform-Update-" + id.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::SET_TRANSFORM, scene);

		H5::Group group = scene.createGroup("Transform-Update-" + id.toString()); // The actual data
		HDF5Typecaster::addNodeTypeInfoToHDF5Group(HDF5Typecaster::TRANSFORM, group);
		HDF5Typecaster::addNodeIdToHDF5Group(id, group);
		HDF5Typecaster::addTransformToHDF5Group(transform, timeStamp, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer setTransform: Cannot create a HDF serialization.";
		return false;
	}

	return true;
}

bool HDF5UpdateSerializer::setUncertainTransform(Id id,
		IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform,
		ITransformUncertainty::ITransformUncertaintyPtr uncertainty,
		TimeStamp timeStamp) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::deleteNode(Id id) {
	LOG(DEBUG) << "HDF5UpdateSerializer: deleting Node-" << id.toString();
	try {
		std::string fileName = "Node-Deletion-" + id.toString() + "-rsg.h5";
		H5::FileAccPropList faplCore;
		faplCore.setCore(fileImageIncremet, storeMessageBackupsOnFileSystem); // toggle in-memory behavior
		H5::H5File file(fileName, H5F_ACC_TRUNC, H5::FileCreatPropList::DEFAULT, faplCore);

		/* Generic/common entry group with general information */
		H5::Group scene = file.createGroup("Scene");
		HDF5Typecaster::addCommandTypeInfoToHDF5Group(HDF5Typecaster::DELETE, scene);

		H5::Group group = scene.createGroup("Node-" + id.toString()); // The actual data
		HDF5Typecaster::addNodeIdToHDF5Group(id, group);

		file.flush(H5F_SCOPE_GLOBAL);
		doSendMessage(file);
		file.close();
//		doSendMessage(fileName);

	} catch (H5::Exception e) {
		LOG(ERROR) << "HDF5UpdateSerializer setTransform: Cannot create a HDF serialization.";
		return false;
	}

	return true;
}

bool HDF5UpdateSerializer::addParent(Id id, Id parentId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::removeParent(Id id, Id parentId) {
	LOG(ERROR) << "HDF5UpdateSerializer: functionality not yet implemented.";
	return false;
}

bool HDF5UpdateSerializer::doSendMessage(std::string messageName) {
	std::ifstream inputFile;
	inputFile.open(messageName.c_str(), std::ios::binary);

	if(!inputFile.is_open()) {
		LOG(ERROR) << "Cannot open file" << messageName <<". Aborting.";
		return false;
	}

	/* get length of file */
	inputFile.seekg (0, std::ios::end);
	long length = inputFile.tellg();
	inputFile.seekg (0, std::ios::beg);
	LOG(DEBUG) << "HDF5UpdateSerializer: Sending message " << messageName << " with length " << length;

	char *buffer = new char [length];
	inputFile.read (buffer,length); // a single bunch of data is feed into the buffer
	inputFile.close();
	LOG(DEBUG) << "HDF5UpdateSerializer: prepared byte stream.";

	int transferredBytes;
	int returnValue =  port->write(buffer, length, transferredBytes);
	LOG(DEBUG) << "HDF5UpdateSerializer: \t" << transferredBytes << " bytes transferred.";

	delete buffer;
	return true;
}

bool HDF5UpdateSerializer::doSendMessage(H5::H5File message) {
	ssize_t fileSize = -1;
//	ssize_t numberOfBytesRead;

//	fileSize = message.getFileSize();
    fileSize = H5Fget_file_image(message.getId(), NULL, 0);
	LOG(DEBUG) << "HDF5UpdateSerializer (VFD): Sending message with length " << fileSize;

	char *buffer = new char [fileSize];
    H5Fget_file_image(message.getId(), buffer, fileSize);
	LOG(DEBUG) << "HDF5UpdateSerializer (VFD): prepared byte stream with length " << fileSize;

	int transferredBytes;
	int returnValue =  port->write(buffer, fileSize, transferredBytes);
	LOG(DEBUG) << "HDF5UpdateSerializer (VFD): \t" << transferredBytes << " bytes transferred.";

	delete buffer;
	return true;
}

} /* namespace rsg */
} /* namespace brics_3d */
/* EOF */
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1668
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1091046 by johtaylo@johtaylo-JTBUILDER03-increment on 2014/10/27 03:00:16<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1669
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3000
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 2000779 by chui@ocl-promo-incrementor on 2019/09/19 03:00:42<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3001
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2554
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1493128 by johtaylo@johtaylo-jtincrementor2-increment on 2017/12/12 03:00:05<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2555
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2360
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1371152 by johtaylo@johtaylo-jtincrementor-increment on 2017/02/09 03:00:05<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2361
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3059
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 2043798 by chui@ocl-promo-incrementor on 2019/12/11 03:00:04<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3060
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2965
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1979295 by chui@ocl-promo-incrementor on 2019/08/07 03:00:20<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2966
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtDBus/QDBusServiceWatcher>
#include <QtDBus>
#include <QtTest>

class tst_QDBusServiceWatcher: public QObject
{
    Q_OBJECT
    QString serviceName;
public:
    tst_QDBusServiceWatcher();

private slots:
    void initTestCase();
    void cleanup();

    void watchForCreation();
    void watchForDisappearance();
    void watchForOwnerChange();
    void modeChange();
};

tst_QDBusServiceWatcher::tst_QDBusServiceWatcher()
    : serviceName("com.example.TestName")
{
}

void tst_QDBusServiceWatcher::initTestCase()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());
}

void tst_QDBusServiceWatcher::cleanup()
{
    // ensure that the name isn't registered
    QDBusConnection::sessionBus().unregisterService(serviceName);
}

void tst_QDBusServiceWatcher::watchForCreation()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceRegistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());

    spyR.clear();
    spyU.clear();
    spyO.clear();

    // unregister it:
    con.unregisterService(serviceName);

    // and register again
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());
}

void tst_QDBusServiceWatcher::watchForDisappearance()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForUnregistration);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceUnregistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    // unregister it:
    con.unregisterService(serviceName);

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 0);

    QCOMPARE(spyU.count(), 1);
    QCOMPARE(spyU.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QCOMPARE(spyO.at(0).at(1).toString(), con.baseService());
    QVERIFY(spyO.at(0).at(2).toString().isEmpty());
}

void tst_QDBusServiceWatcher::watchForOwnerChange()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForOwnerChange);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceRegistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());

    spyR.clear();
    spyU.clear();
    spyO.clear();

    // unregister it:
    con.unregisterService(serviceName);

    // and register again
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 1);
    QCOMPARE(spyU.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyO.count(), 2);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QCOMPARE(spyO.at(0).at(1).toString(), con.baseService());
    QVERIFY(spyO.at(0).at(2).toString().isEmpty());
    QCOMPARE(spyO.at(1).at(0).toString(), serviceName);
    QVERIFY(spyO.at(1).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(1).at(2).toString(), con.baseService());
}

void tst_QDBusServiceWatcher::modeChange()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceRegistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());

    spyR.clear();
    spyU.clear();
    spyO.clear();

    watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);

    // unregister it:
    con.unregisterService(serviceName);

    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceUnregistered(QString)), SLOT(exitLoop()));
    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 0);

    QCOMPARE(spyU.count(), 1);
    QCOMPARE(spyU.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QCOMPARE(spyO.at(0).at(1).toString(), con.baseService());
    QVERIFY(spyO.at(0).at(2).toString().isEmpty());
}

QTEST_MAIN(tst_QDBusServiceWatcher)
#include "tst_qdbusservicewatcher.moc"
<commit_msg>Autotest: Change the service name we're testing between tests.<commit_after>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtDBus/QDBusServiceWatcher>
#include <QtDBus>
#include <QtTest>

class tst_QDBusServiceWatcher: public QObject
{
    Q_OBJECT
    QString serviceName;
    int testCounter;
public:
    tst_QDBusServiceWatcher();

private slots:
    void initTestCase();
    void init();

    void watchForCreation();
    void watchForDisappearance();
    void watchForOwnerChange();
    void modeChange();
};

tst_QDBusServiceWatcher::tst_QDBusServiceWatcher()
    : testCounter(0)
{
}

void tst_QDBusServiceWatcher::initTestCase()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());
}

void tst_QDBusServiceWatcher::init()
{
    // change the service name from test to test
    serviceName = "com.example.TestService" + QString::number(testCounter++);
}

void tst_QDBusServiceWatcher::watchForCreation()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceRegistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());

    spyR.clear();
    spyU.clear();
    spyO.clear();

    // unregister it:
    con.unregisterService(serviceName);

    // and register again
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());
}

void tst_QDBusServiceWatcher::watchForDisappearance()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForUnregistration);
    watcher.setObjectName("watcher for disappearance");

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceUnregistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    // unregister it:
    con.unregisterService(serviceName);

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 0);

    QCOMPARE(spyU.count(), 1);
    QCOMPARE(spyU.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QCOMPARE(spyO.at(0).at(1).toString(), con.baseService());
    QVERIFY(spyO.at(0).at(2).toString().isEmpty());
}

void tst_QDBusServiceWatcher::watchForOwnerChange()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForOwnerChange);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceRegistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());

    spyR.clear();
    spyU.clear();
    spyO.clear();

    // unregister it:
    con.unregisterService(serviceName);

    // and register again
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 1);
    QCOMPARE(spyU.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyO.count(), 2);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QCOMPARE(spyO.at(0).at(1).toString(), con.baseService());
    QVERIFY(spyO.at(0).at(2).toString().isEmpty());
    QCOMPARE(spyO.at(1).at(0).toString(), serviceName);
    QVERIFY(spyO.at(1).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(1).at(2).toString(), con.baseService());
}

void tst_QDBusServiceWatcher::modeChange()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QVERIFY(con.isConnected());

    QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration);

    QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString)));
    QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString)));
    QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceRegistered(QString)), SLOT(exitLoop()));

    // register a name
    QVERIFY(con.registerService(serviceName));

    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 1);
    QCOMPARE(spyR.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyU.count(), 0);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QVERIFY(spyO.at(0).at(1).toString().isEmpty());
    QCOMPARE(spyO.at(0).at(2).toString(), con.baseService());

    spyR.clear();
    spyU.clear();
    spyO.clear();

    watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);

    // unregister it:
    con.unregisterService(serviceName);

    QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceUnregistered(QString)), SLOT(exitLoop()));
    QTestEventLoop::instance().enterLoop(1);
    QVERIFY(!QTestEventLoop::instance().timeout());

    QCOMPARE(spyR.count(), 0);

    QCOMPARE(spyU.count(), 1);
    QCOMPARE(spyU.at(0).at(0).toString(), serviceName);

    QCOMPARE(spyO.count(), 1);
    QCOMPARE(spyO.at(0).at(0).toString(), serviceName);
    QCOMPARE(spyO.at(0).at(1).toString(), con.baseService());
    QVERIFY(spyO.at(0).at(2).toString().isEmpty());
}

QTEST_MAIN(tst_QDBusServiceWatcher)
#include "tst_qdbusservicewatcher.moc"
<|endoftext|>


<commit_before>/***********************************************************************
    filename:   CEGUIDefaultLogger.cpp
    created:    25/1/2006
    author:     Andrew Zabolotny

    purpose:    Implementation of the DefaultLogger class
*************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
 *
 *   Permission is hereby granted, free of charge, to any person obtaining
 *   a copy of this software and associated documentation files (the
 *   "Software"), to deal in the Software without restriction, including
 *   without limitation the rights to use, copy, modify, merge, publish,
 *   distribute, sublicense, and/or sell copies of the Software, and to
 *   permit persons to whom the Software is furnished to do so, subject to
 *   the following conditions:
 *
 *   The above copyright notice and this permission notice shall be
 *   included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 ***************************************************************************/
#include "CEGUIDefaultLogger.h"
#include <ctime>
#include <iomanip>

// Start of CEGUI namespace section
namespace CEGUI
{

    /*************************************************************************
        Constructor
    *************************************************************************/
    DefaultLogger::DefaultLogger(void) :
            d_caching(true)
    {
        // create log header
        logEvent("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
        logEvent("+                     Crazy Eddie's GUI System - Event log                    +");
        logEvent("+                          (http://www.cegui.org.uk/)                         +");
        logEvent("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
        char addr_buff[32];
        sprintf(addr_buff, "(%p)", static_cast<void*>(this));
        logEvent("CEGUI::Logger singleton created. " + String(addr_buff));
    }

    /*************************************************************************
        Destructor
    *************************************************************************/
    DefaultLogger::~DefaultLogger(void)
    {
        if (d_ostream.is_open())
        {
            char addr_buff[32];
            sprintf(addr_buff, "(%p)", static_cast<void*>(this));
            logEvent("CEGUI::Logger singleton destroyed. " + String(addr_buff));
            d_ostream.close();
        }
    }

    /*************************************************************************
        Logs an event
    *************************************************************************/
    void DefaultLogger::logEvent(const String& message, LoggingLevel level /* = Standard */)
    {
        using namespace std;

        time_t  et;
        time(&et);
        tm* etm = localtime(&et);

        if (etm)
        {
            // clear sting stream
            d_workstream.str("");

            // write date
            d_workstream << setfill('0') << setw(2) << etm->tm_mday << '/' <<
            setfill('0') << setw(2) << 1 + etm->tm_mon << '/' <<
            setw(4) << (1900 + etm->tm_year) << ' ';

            // write time
            d_workstream << setfill('0') << setw(2) << etm->tm_hour << ':' <<
            setfill('0') << setw(2) << etm->tm_min << ':' <<
            setfill('0') << setw(2) << etm->tm_sec << ' ';

            // write event type code
            switch(level)
            {
            case Errors:
                d_workstream << "(Error)\t";
                break;

            case Warnings:
                d_workstream << "(Warn)\t";
                break;

            case Standard:
                d_workstream << "(Std) \t";
                break;

            case Informative:
                d_workstream << "(Info) \t";
                break;

            case Insane:
                d_workstream << "(Insan)\t";
                break;

            default:
                d_workstream << "(Unkwn)\t";
                break;
            }

            d_workstream << message << endl;

            if (d_caching)
            {
                d_cache.push_back(std::make_pair(d_workstream.str().c_str(), level));
            }
            else if (d_level >= level)
            {
                // write message
                d_ostream << d_workstream.str();
                // ensure new event is written to the file, rather than just being buffered.
                d_ostream.flush();
            }
        }
    }

    void DefaultLogger::setLogFilename(const String& filename, bool append)
    {
        // close current log file (if any)
        if (d_ostream.is_open())
        {
            d_ostream.close();
        }

        d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));

        if (!d_ostream)
        {
            CEGUI_THROW("Logger::setLogFilename - Failed to open file.");
        }

        // initialise width for date & time alignment.
        d_ostream.width(2);

        // write out cached log strings.
        if (d_caching)
        {
            d_caching = false;

            Cache::iterator iter = d_cache.begin();

            while (iter != d_cache.end())
            {
                if (d_level >= (*iter).second)
                {
                    // write message
                    d_ostream << (*iter).first;
                    // ensure new event is written to the file, rather than just being buffered.
                    d_ostream.flush();
                }

                ++iter;
            }

            d_cache.clear();
        }
    }

} // End of  CEGUI namespace section
<commit_msg>MOD: DefaultLogger::setLogFilename throws char*, changed to throw FileIOException<commit_after>/***********************************************************************
    filename:   CEGUIDefaultLogger.cpp
    created:    25/1/2006
    author:     Andrew Zabolotny

    purpose:    Implementation of the DefaultLogger class
*************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
 *
 *   Permission is hereby granted, free of charge, to any person obtaining
 *   a copy of this software and associated documentation files (the
 *   "Software"), to deal in the Software without restriction, including
 *   without limitation the rights to use, copy, modify, merge, publish,
 *   distribute, sublicense, and/or sell copies of the Software, and to
 *   permit persons to whom the Software is furnished to do so, subject to
 *   the following conditions:
 *
 *   The above copyright notice and this permission notice shall be
 *   included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 ***************************************************************************/
#include "CEGUIDefaultLogger.h"
#include "CEGUIExceptions.h"
#include <ctime>
#include <iomanip>

// Start of CEGUI namespace section
namespace CEGUI
{

    /*************************************************************************
        Constructor
    *************************************************************************/
    DefaultLogger::DefaultLogger(void) :
            d_caching(true)
    {
        // create log header
        logEvent("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
        logEvent("+                     Crazy Eddie's GUI System - Event log                    +");
        logEvent("+                          (http://www.cegui.org.uk/)                         +");
        logEvent("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
        char addr_buff[32];
        sprintf(addr_buff, "(%p)", static_cast<void*>(this));
        logEvent("CEGUI::Logger singleton created. " + String(addr_buff));
    }

    /*************************************************************************
        Destructor
    *************************************************************************/
    DefaultLogger::~DefaultLogger(void)
    {
        if (d_ostream.is_open())
        {
            char addr_buff[32];
            sprintf(addr_buff, "(%p)", static_cast<void*>(this));
            logEvent("CEGUI::Logger singleton destroyed. " + String(addr_buff));
            d_ostream.close();
        }
    }

    /*************************************************************************
        Logs an event
    *************************************************************************/
    void DefaultLogger::logEvent(const String& message, LoggingLevel level /* = Standard */)
    {
        using namespace std;

        time_t  et;
        time(&et);
        tm* etm = localtime(&et);

        if (etm)
        {
            // clear sting stream
            d_workstream.str("");

            // write date
            d_workstream << setfill('0') << setw(2) << etm->tm_mday << '/' <<
            setfill('0') << setw(2) << 1 + etm->tm_mon << '/' <<
            setw(4) << (1900 + etm->tm_year) << ' ';

            // write time
            d_workstream << setfill('0') << setw(2) << etm->tm_hour << ':' <<
            setfill('0') << setw(2) << etm->tm_min << ':' <<
            setfill('0') << setw(2) << etm->tm_sec << ' ';

            // write event type code
            switch(level)
            {
            case Errors:
                d_workstream << "(Error)\t";
                break;

            case Warnings:
                d_workstream << "(Warn)\t";
                break;

            case Standard:
                d_workstream << "(Std) \t";
                break;

            case Informative:
                d_workstream << "(Info) \t";
                break;

            case Insane:
                d_workstream << "(Insan)\t";
                break;

            default:
                d_workstream << "(Unkwn)\t";
                break;
            }

            d_workstream << message << endl;

            if (d_caching)
            {
                d_cache.push_back(std::make_pair(d_workstream.str().c_str(), level));
            }
            else if (d_level >= level)
            {
                // write message
                d_ostream << d_workstream.str();
                // ensure new event is written to the file, rather than just being buffered.
                d_ostream.flush();
            }
        }
    }

    void DefaultLogger::setLogFilename(const String& filename, bool append)
    {
        // close current log file (if any)
        if (d_ostream.is_open())
        {
            d_ostream.close();
        }

        d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));

        if (!d_ostream)
        {
            CEGUI_THROW(FileIOException("Failed to open file '" + filename + "' for writing"));
        }

        // initialise width for date & time alignment.
        d_ostream.width(2);

        // write out cached log strings.
        if (d_caching)
        {
            d_caching = false;

            Cache::iterator iter = d_cache.begin();

            while (iter != d_cache.end())
            {
                if (d_level >= (*iter).second)
                {
                    // write message
                    d_ostream << (*iter).first;
                    // ensure new event is written to the file, rather than just being buffered.
                    d_ostream.flush();
                }

                ++iter;
            }

            d_cache.clear();
        }
    }

} // End of  CEGUI namespace section
<|endoftext|>