| 149 | } // namespace detail |
| 150 | |
| 151 | PythonPluginInstance::PythonPluginInstance(const ExternalFile& externalfile, const std::string& pluginClassName) |
| 152 | : ResourceObject(PythonPluginInstance::iddObjectType(), externalfile.model()) { |
| 153 | OS_ASSERT(getImpl<detail::PythonPluginInstance_Impl>()); |
| 154 | |
| 155 | auto filePath = externalfile.filePath(); |
| 156 | bool ok = (toString(filePath.extension()) == ".py"); |
| 157 | if (!ok) { |
| 158 | remove(); |
| 159 | LOG_AND_THROW("External file must have a .py extension, got externalfile='" << filePath << "'."); |
| 160 | } |
| 161 | |
| 162 | ok = setPointer(OS_PythonPlugin_InstanceFields::ExternalFileName, externalfile.handle()); |
| 163 | OS_ASSERT(ok); |
| 164 | |
| 165 | // This must occur after setPointer externalfile |
| 166 | ok = setPluginClassName(pluginClassName); |
| 167 | if (!ok) { |
| 168 | remove(); |
| 169 | LOG_AND_THROW("Cannot find the Plugin Class Name '" << pluginClassName << "' in external file '" << filePath << "'."); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | IddObjectType PythonPluginInstance::iddObjectType() { |
| 174 | return {IddObjectType::OS_PythonPlugin_Instance}; |