[ome-devel] Saving File attachements to an Image in C++

Josh Moore josh.moore at gmx.de
Tue Jun 8 13:14:53 BST 2010


Hi Jerome,

with $ gcc --version
gcc (GCC) 4.1.2 (Gentoo 4.1.2 p1.3)

I can't get the (OriginalFilePtr&) line to even compile, so I'm not sure 
what your compiler is doing with that statement. Could you add something 
like:

if (!originalFile) {
   cout << "file is null";
}

to find out? Better yet, what do you get when using the Ice-generated 
dynamicCasts?

   originalFile =
   OriginalFilePtr::dynamicCast(up->saveAndReturnObject());

saveAndReturnObject should never return an object for which:

  obj->getId()->getValue()

throws an exception, which is why I assume the issue is the cast. Note 
also: here you could save yourself the cast by saving as:

  omero::model::IObjectPtr obj = query->findByQuery();
  obj->getId()->getValue();

Finally, what exception handling do you have in place and what kind of 
crash are you getting?

Cheers,
~Josh.

On 6/8/10 12:11 PM, Jerome Avondo wrote:
>
> Hi all,
>
> I am trying to save a movie file to an image via the C++ API. I have code to do this in Java so I am trying to reproduce this functionality in C++ but am struggling....
>
> My code logic is as follows,
>
>   omero::model::OriginalFilePtr originalFile = new omero::model::OriginalFileI();
>
>   //omero::model::FormatPtr f = (omero::model::FormatPtr&)query->findByString("omero.model.Format", "value", "video/mpeg");
>   omero::model::FormatPtr f = (omero::model::FormatPtr&) query->findByQuery("from Format as f where f.value='video/mpeg'", 0);
>
>   originalFile->setName(rstring(movieFile));
>   originalFile->setPath(rstring(fullPath));
>   originalFile->setSize(rlong(size));
>   originalFile->setSha1(rstring("pending"));
>   originalFile->setFormat(f);
>
>   originalFile = (omero::model::OriginalFilePtr&) up->saveAndReturnObject(originalFile);
>
>   rawfilestore->setFileId(originalFile->getId()->getValue());
>
> However my originalFile object seems to be wrong/incorrect, as the call to originalFile->getId()->getValue() is causing a crash.
> Is the above calls the minimum I need to create an OriginalFile object?
> I'm running in circles at this end :)
>
> Thanks!
>
> J.



More information about the ome-devel mailing list