/******************************************************************************
** Copyright (c) 2018 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/

//! \file DatabaseRequestHandler
//! \brief Contains the osg::DatabaseRequestHandler class
//! \ingroup osg

#pragma once

#include <osg/Node>

namespace osg
{
	class PagedLOD;

	/** Callback for managing database paging, such as generated by PagedLOD nodes.*/
	class DatabaseRequestHandler : public osg::Referenced
	{
	public:

		DatabaseRequestHandler() 
			: Referenced(true) 
		{
			// nop
		}

		virtual void requestNodeFile(const std::string& fileName, osg::NodePath& nodePath, float priority, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& databaseRequest, const osg::Referenced* options = 0) = 0;

	protected:
		virtual ~DatabaseRequestHandler() 
		{
			// nop
		}
	};

	class DatabaseRequestHandlerCallback : public osg::Referenced
	{
	public:
		//! Called before a node is added to the live scene graph, possibly from a background pager thread
		//! The child may be replaced (e.g. cloned and some operations (e.g. flattening/indirecting) may get
		//! done on it. In which case, the returned node is non-null and is what will get ultimately 
		//! added to the scenegraph. The default handling sets the returned node to 0
		virtual void childLoaded(const DatabaseRequestHandler*, const osg::Group* page, osg::Node* child, const std::string& fileName, osg::Node*& returnedNode) const
		{
			returnedNode = 0;
		}

		/* child under page was added to the scenegraph */
		virtual void childPagedIn(const DatabaseRequestHandler*, osg::PagedLOD* page, osg::Node* child) const = 0;

		/* child under page was un-loaded and is about to be removed from the scenegraph */
		virtual void childAboutToPageOut(const DatabaseRequestHandler*, osg::PagedLOD* page, osg::Node* child) const = 0;

		virtual DatabaseRequestHandlerCallback* clone() const = 0;
	protected:
		virtual ~DatabaseRequestHandlerCallback(){}
		DatabaseRequestHandlerCallback() : Referenced(true){}
		DatabaseRequestHandlerCallback(const DatabaseRequestHandlerCallback&){}
	};
}