About Working with the Capture State

In addition to the user's controls for the Screencast Recording Utility, your application can start, stop, pause, and resume video capture.

Using an active query, you can also determine the current state of the capture process, whether the state was changed programmatically or by the user.
#include <Chronicle/Chronicle.h>

// Controlling the capture

Chronicle::Error err;

err = Chronicle::Facade::startCapture();
err = Chronicle::Facade::pauseCapture();
err = Chronicle::Facade::resumeCapture();
err = Chronicle::Facade::stopCapture();

// Querying the capture state

bool flag;

flag = Chronicle::Facade::isCapturing();
flag = Chronicle::Facade::isCapturePaused();
flag = Chronicle::Facade::canStartCapture();
flag = Chronicle::Facade::canPauseCapture();
flag = Chronicle::Facade::canResumeCapture();
flag = Chronicle::Facade::canStopCapture();

The sample code shows examples of startup() and shutdown() functions that call initialize() before creating the Facade Observer and then remove the Observer before calling cleanup().

The MyObserver() functions addToFacade() and removeFromFacade() used in startup() and shutdown() are not used by the Screencast Recorder and are used here only as examples.
#include <Chronicle/Chronicle.h>
#include <iostream>
using namespace std;

// FacadeObserver subclass

class MyObserver : public Chronicle::Facade::Observer
{
private:
		MyObserver(); 

public:
		static bool addToFacade();
		static void removeFromFacade();
		virtual void captureStarted();
		virtual void capturePaused();
		virtual void captureResumed();
		virtual void captureStopped();

private:
	static MyObserver *s_this;
};

MyObserver *s_this = NULL;
MyObserver::MyObserver()
{
}

bool MyObserver::addToFacade()
{
	if (s_this)
		return true;

	s_this = new MyObserver;
	if (Chronicle::Facade::addObserver(s_this) == Chronicle::NoError)
		return true;

	delete s_this;
	s_this = NULL;

	return false;
}

void MyObserver::removeFromFacade()
{
	if (s_this)
	{
		Chronicle::Facade::removeObserver(s_this);
		delete s_this;	
		s_this = NULL;
	}
}

void MyObserver::captureStarted()
{
	// Warning: the notification handler is called from a separate worker thread
	count << "capture started";
}

void MyObserver::capturePaused()
{
	// Warning: the notification handler is called from a separate worker thread	
	count << "capture paused";
}

void MyObserver::captureResumed()
{
	// Warning: the notification handler is called from a separate worker thread
	count << "capture resumed";
}

void MyObserver::captureStopped()
{
	// Warning: the notification handler is called from a separate worker thread
	count << "capture stopped";
}

// Add observer to Facade after initialization

void startup()
{
	Chronicle::Error err = Chronicle::Facade::initialize();
	if (err == Chronicle::NoError)
	{
		MyObserver::addToFacade();
	}
}

// Remove observer before Facade cleanup

void shutdown()
{
	MyObserver::removeFromFacade();
	Chronicle::Facade::cleanup();
}