FileFormat::FileFormat( const String& nameExtOrMime, bool toRead, bool toWrite ) : FileFormatBase() { if ( nameExtOrMime.IsEmpty() ) throw Error( "FileFormat: Empty format name, file extension or MIME type specified" ); m_data = new FileFormatPrivate; if ( nameExtOrMime.Contains( '/' ) ) { IsoString mimeType( nameExtOrMime ); m_data->handle = (*API->FileFormat->GetFileFormatByMimeType)( ModuleHandle(), mimeType.c_str(), toRead, toWrite ); if ( m_data->handle == nullptr ) throw Error( "FileFormat: No installed image file format was found " "for the specified MIME type \'" + nameExtOrMime + "\' and access conditions" ); } else if ( nameExtOrMime.StartsWith( '.' ) ) { m_data->handle = (*API->FileFormat->GetFileFormatByFileExtension)( ModuleHandle(), nameExtOrMime.c_str(), toRead, toWrite ); if ( m_data->handle == nullptr ) throw Error( "FileFormat: No installed image file format was found " "for the specified file extension \'" + nameExtOrMime + "\'and access conditions" ); } else { IsoString id( nameExtOrMime ); m_data->handle = (*API->FileFormat->GetFileFormatByName)( ModuleHandle(), id.c_str() ); if ( m_data->handle == nullptr ) throw Error( "FileFormat: No installed image file format was found " "with the specified identifier \'" + nameExtOrMime + '\'' ); } m_data->GetCapabilities(); }
XnStatus RecorderImpl::AddRawNode(const XnChar* strNodeName) { if (IsRawNode(strNodeName)) { xnLogWarning(XN_MASK_OPEN_NI, "Attempted to add a raw node by name of '%s' but there is already a raw node by that name", strNodeName); XN_ASSERT(FALSE); return XN_STATUS_INVALID_OPERATION; } XnNodeHandle hNode = NULL; NodeWatcher* pNodeWatcher = NULL; if ((xnGetNodeHandleByName(m_hRecorder->pContext, strNodeName, &hNode) == XN_STATUS_OK) && (m_nodeWatchersMap.Get(hNode, pNodeWatcher) == XN_STATUS_OK)) { //There's a node by that name and we're already watching it xnLogWarning(XN_MASK_OPEN_NI, "Attempted to add a raw node by name of '%s' but there is already another node by that name that is being recorded", strNodeName); XN_ASSERT(FALSE); return XN_STATUS_INVALID_OPERATION; } XnStatus nRetVal = Notifications().OnNodeAdded(ModuleHandle(), strNodeName, (XnProductionNodeType)0, XN_CODEC_UNCOMPRESSED); XN_IS_STATUS_OK(nRetVal); RawNodeInfo rawNodeInfo; nRetVal = m_rawNodesMap.Set(strNodeName, rawNodeInfo); XN_IS_STATUS_OK(nRetVal); return XN_STATUS_OK; }
Variant::data_type View::PropertyType( const IsoString& property ) const { uint64 type = 0; if ( (*API->View->GetViewPropertyAttributes)( ModuleHandle(), handle, property.c_str(), 0/*flags*/, &type ) == api_false ) throw APIFunctionError( "GetViewPropertyAttributes" ); return VariantTypeFromAPIPropertyType( type ); }
ViewPropertyAttributes View::PropertyAttributes( const IsoString& property ) const { uint32 flags = 0; if ( (*API->View->GetViewPropertyAttributes)( ModuleHandle(), handle, property.c_str(), &flags, 0/*type*/ ) == api_false ) throw APIFunctionError( "GetViewPropertyAttributes" ); return ViewPropertyAttributes( ViewPropertyAttribute::mask_type( flags ) ); }
Variant View::ComputeProperty( const IsoString& property, bool notify ) { api_property_value value; if ( (*API->View->ComputeViewProperty)( ModuleHandle(), handle, property.c_str(), notify, &value ) == api_false ) throw APIFunctionError( "ComputeViewProperty" ); return VariantFromAPIPropertyValue( value ); }
void View::SetPropertyValue( const IsoString& property, const Variant& value, bool notify, ViewPropertyAttributes attributes ) { api_property_value apiValue; APIPropertyValueFromVariant( apiValue, value ); if ( (*API->View->SetViewPropertyValue)( ModuleHandle(), handle, property.c_str(), &apiValue, attributes, notify ) == api_false ) throw APIFunctionError( "SetViewPropertyValue" ); }
Variant View::PropertyValue( const IsoString& property ) const { api_property_value value; if ( (*API->View->GetViewPropertyValue)( ModuleHandle(), handle, property.c_str(), &value ) == api_false ) throw APIFunctionError( "GetViewPropertyValue" ); return VariantFromAPIPropertyValue( value ); }
XnStatus PlayerImpl::SetSource(XnRecordMedium sourceType, const XnChar* strSource) { XnStatus nRetVal = XN_STATUS_OK; // NOTE: we don't want playback speed to affect getting to the first frame, so perform this // without playback speed XnDouble dPlaybackSpeed = GetPlaybackSpeed(); SetPlaybackSpeed(XN_PLAYBACK_SPEED_FASTEST); //Right now the only record medium we support is a file m_sourceType = sourceType; switch (m_sourceType) { case XN_RECORD_MEDIUM_FILE: { nRetVal = xnOSStrCopy(m_strSource, strSource, sizeof(m_strSource)); XN_IS_STATUS_OK(nRetVal); nRetVal = ModulePlayer().SetInputStream(ModuleHandle(), this, &s_fileInputStream); XN_IS_STATUS_OK(nRetVal); break; } default: XN_ASSERT(FALSE); return XN_STATUS_BAD_PARAM; } // now re-set playback speed nRetVal = SetPlaybackSpeed(dPlaybackSpeed); XN_IS_STATUS_OK(nRetVal); return XN_STATUS_OK; }
BitmapBox::BitmapBox( const Bitmap& bm, Control& parent ) : Frame( (*API->BitmapBox->CreateBitmapBox)( ModuleHandle(), this, bm.handle, parent.handle, 0 /*flags*/ ) ) { if ( handle == 0 ) throw APIFunctionError( "CreateBitmapBox" ); }
ToolButton::ToolButton( const String& text, const pcl::Bitmap& icon, bool checkable, Control& parent ) : Button( (*API->Button->CreateToolButton)( ModuleHandle(), this, text.c_str(), icon.handle, checkable, parent.handle, 0 /*flags*/ ) ) { if ( handle == 0 ) throw APIFunctionError( "CreateToolButton" ); }
Slider::Slider( Control& parent, bool vertical ) : Control( (*API->Slider->CreateSlider)( ModuleHandle(), this, vertical, parent.handle, 0 /*flags*/ ) ), onValueUpdated( 0 ), onRangeUpdated( 0 ) { if ( handle == 0 ) throw APIFunctionError( "CreateSlider" ); }
Dialog::Dialog( Control& parent ) : Control( (*API->Dialog->CreateDialog)( ModuleHandle(), this, parent.handle, 0 /*flags*/ ) ), onExecute( 0 ), onReturn( 0 ) { if ( handle == 0 ) throw APIFunctionError( "CreateDialog" ); }
Timer::Timer() : UIObject( (*API->Timer->CreateTimer)( ModuleHandle(), this, 0/*flags*/ ) ), onTimer( 0 ), count( 0 ) { if ( handle == 0 ) throw APIFunctionError( "CreateTimer" ); }
TreeBox::Node::Node( TreeBox& parentTree, int index ) : UIObject( (*API->TreeBox->CreateTreeBoxNode)( ModuleHandle(), this ) ) { if ( IsNull() ) throw APIFunctionError( "CreateTreeBoxNode" ); if ( !parentTree.IsNull() ) parentTree.Insert( index, this ); }
String ProcessInstance::ToSource( const IsoString& language, const IsoString& varId, int indent ) const { char16_type* s = (*API->Process->GetProcessInstanceSourceCode)( ModuleHandle(), handle, language.c_str(), varId.c_str(), indent ); if ( s == 0 ) throw APIFunctionError( "GetProcessInstanceSourceCode" ); String source( s ); Module->Deallocate( s ); return source; }
XnStatus RecorderImpl::NotifyRawNodeStateReady(const XnChar* strNodeName) { if (!IsRawNode(strNodeName)) { xnLogWarning(XN_MASK_OPEN_NI, "There is no node by the name of '%s'", strNodeName); XN_ASSERT(FALSE); return XN_STATUS_NO_MATCH; } return Notifications().OnNodeStateReady(ModuleHandle(), strNodeName); }
XnStatus RecorderImpl::SetRawNodeGeneralProp(const XnChar* strNodeName, const XnChar* strPropName, XnUInt32 nBufferSize, const void* pBuffer) { if (!IsRawNode(strNodeName)) { xnLogWarning(XN_MASK_OPEN_NI, "Tried to set property of non-existing node by the name of '%s'", strNodeName); XN_ASSERT(FALSE); return XN_STATUS_NO_MATCH; } return Notifications().OnNodeGeneralPropChanged(ModuleHandle(), strNodeName, strPropName, nBufferSize, pBuffer); }
XnStatus RecorderImpl::SetRawNodeNewData(const XnChar* strNodeName, XnUInt64 nTimeStamp, XnUInt32 nFrame, const void* pData, XnUInt32 nSize) { if (!IsRawNode(strNodeName)) { xnLogWarning(XN_MASK_OPEN_NI, "There is no node by the name of '%s'", strNodeName); XN_ASSERT(FALSE); return XN_STATUS_NO_MATCH; } return Notifications().OnNodeNewData(ModuleHandle(), strNodeName, nTimeStamp, nFrame, pData, nSize); }
XnStatus RecorderImpl::RemoveRawNode(const XnChar* strNodeName) { if (!IsRawNode(strNodeName)) { xnLogWarning(XN_MASK_OPEN_NI, "Tried to remove non-existing raw node by the name of '%s'", strNodeName); XN_ASSERT(FALSE); return XN_STATUS_NO_MATCH; } return Notifications().OnNodeRemoved(ModuleHandle(), strNodeName); }
XnStatus PlayerImpl::Init(XnNodeHandle hPlayer) { XN_VALIDATE_PTR(hPlayer, XN_STATUS_ERROR); XnModuleInstance* pModuleInstance = hPlayer->pModuleInstance; XN_VALIDATE_PTR(pModuleInstance, XN_STATUS_ERROR); XnModuleNodeHandle hModule = pModuleInstance->hNode; XN_VALIDATE_PTR(hModule, XN_STATUS_ERROR); XN_VALIDATE_PTR(pModuleInstance->pLoaded, XN_STATUS_ERROR); XN_VALIDATE_PTR(pModuleInstance->pLoaded->pInterface, XN_STATUS_ERROR); m_hPlayer = hPlayer; XnStatus nRetVal = ModulePlayer().SetNodeNotifications(ModuleHandle(), this, &s_nodeNotifications); XN_IS_STATUS_OK(nRetVal); XnCallbackHandle hDummy; // node will be destroyed anyway nRetVal = ModulePlayer().RegisterToEndOfFileReached(ModuleHandle(), EndOfFileReachedCallback, this, &hDummy); XN_IS_STATUS_OK(nRetVal); return XN_STATUS_OK; }
api_bool InternalIconEnumerator::ProcessCallback( const char* iconId, void* data ) { #define enumeration reinterpret_cast<ProcessIconsByProcessIdEnumerationData*>( data ) ProcessInstance instance( (*API->Process->CreateProcessInstanceFromIcon)( ModuleHandle(), iconId ) ); if ( instance.IsNull() ) // ?! should not happen return api_false; if ( instance.ParentProcess().Id() == enumeration->processId ) enumeration->icons.Add( IsoString( iconId ) ); return api_true; #undef enumeration }
String Console::ReadString() { if ( m_thread == 0 ) { char16_type* s = (*API->Global->ReadConsoleString)( ModuleHandle(), m_handle ); if ( s != 0 ) { String str( s ); Module->Deallocate( s ); return str; } } return String(); }
ByteArray ExternalProcess::Read() { /* * ### NB: ExternalProcess::ReadFromExternalProcess allocates the read data * in the module's heap. */ uint8* data = 0; size_type size = 0; if ( (*API->ExternalProcess->ReadFromExternalProcess)( ModuleHandle(), handle, ExternalProcessContext::CombinedOutput, reinterpret_cast<void**>( &data ), &size ) == api_false ) throw APIFunctionError( "ReadFromExternalProcess" ); ByteArray b; b.Import( data, data+size ); return b; }
XnStatus RecorderImpl::AddNode(ProductionNode &node, XnCodecID compression) { if (!node.IsValid()) { return XN_STATUS_BAD_PARAM; } if (compression == XN_CODEC_NULL) { compression = GetDefaultCodecID(node); } XnProductionNodeType type = node.GetInfo().GetDescription().Type; NodeWatcher* pNodeWatcher = NULL; XnStatus nRetVal = CreateNodeWatcher(node, type, ModuleHandle(), Notifications(), pNodeWatcher); XN_IS_STATUS_OK(nRetVal); nRetVal = pNodeWatcher->Register(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pNodeWatcher); return nRetVal; } nRetVal = NotifyNodeAdded(node, type, compression); XN_IS_STATUS_OK(nRetVal); nRetVal = pNodeWatcher->NotifyState(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pNodeWatcher); return nRetVal; } nRetVal = m_nodeWatchersMap.Set(node, pNodeWatcher); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pNodeWatcher); return nRetVal; } return XN_STATUS_OK; }
XnStatus RecorderImpl::SetDestination(XnRecordMedium destType, const XnChar* strDest) { XnStatus nRetVal = XN_STATUS_OK; switch (destType) { //Right now only file destination is supported case XN_RECORD_MEDIUM_FILE: { nRetVal = xnOSStrCopy(m_strFileName, strDest, sizeof(m_strFileName)); XN_IS_STATUS_OK(nRetVal); nRetVal = ModuleRecorder().SetOutputStream(ModuleHandle(), this, &s_fileOutputStream); XN_IS_STATUS_OK(nRetVal); break; } default: XN_ASSERT(FALSE); return XN_STATUS_BAD_PARAM; } return XN_STATUS_OK; }
XnStatus PlayerImpl::SetSource(XnRecordMedium sourceType, const XnChar* strSource) { XnStatus nRetVal = XN_STATUS_OK; m_sourceType = sourceType; //Right now the only record medium we support is a file switch (m_sourceType) { case XN_RECORD_MEDIUM_FILE: { nRetVal = xnOSStrCopy(m_strSource, strSource, sizeof(m_strSource)); XN_IS_STATUS_OK(nRetVal); nRetVal = ModulePlayer().SetInputStream(ModuleHandle(), this, &s_fileInputStream); XN_IS_STATUS_OK(nRetVal); break; } default: XN_ASSERT(FALSE); return XN_STATUS_BAD_PARAM; } return XN_STATUS_OK; }
static void Initialize() { static AtomicInt s_initialized; static Mutex s_mutex; if ( !s_initialized ) { volatile AutoLock lock( s_mutex ); if ( s_initialized.Load() == 0 ) { uint32 M, m, r, b, beta, conf, le; char lang[ 8 ]; (*API->Global->GetPixInsightVersion)( &M, &m, &r, &b, &beta, &conf, &le, lang ); s_major = int( M ); s_minor = int( m ); s_release = int( r ); s_build = int( b ); s_beta = int( beta ); s_confidential = conf != 0; s_le = le != 0; s_language = lang; #if ( PCL_API_Version >= 0x0126 ) char16_type* s = (*API->Global->GetPixInsightCodename)( ModuleHandle() ); if ( s != nullptr ) { s_codename = String( s ); if ( Module != nullptr ) Module->Deallocate( s ); } #endif s_initialized.Store( 1 ); } } }
ProcessInstance::ProcessInstance( const Process& process ) : UIObject( (*API->Process->CreateProcessInstance)( ModuleHandle(), process.Handle() ) ) { if ( handle == 0 ) throw APIFunctionError( "CreateProcessInstance" ); }
void* ProcessInstance::CloneHandle() const { return (*API->Process->CloneProcessInstance)( ModuleHandle(), handle, 0/*flags*/ ); }
ProcessInstance ProcessInstance::FromIcon( const IsoString& iconId ) { return ProcessInstance( (*API->Process->CreateProcessInstanceFromIcon)( ModuleHandle(), iconId.c_str() ) ); }