GridFileWrapper.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::CommonStorage
17 * @author Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "GridFileWrapper.h"
24 #include <IceUtil/UUID.h>
27 
28 #include <mongo/client/dbclient.h>
29 
30 using namespace memoryx;
31 
32 GridFileWrapper::GridFileWrapper(const mongo::GridFile& gridFile, const std::shared_ptr<std::mutex>& accessGridFSFilesMutex) :
33  gridFile(new mongo::GridFile(gridFile)),
34  nextChunkNo(0),
35  accessGridFSFilesMutex(accessGridFSFilesMutex)
36 {
37  iceId.name = IceUtil::generateUUID();
38 }
39 
41  = default;
42 
43 std::string GridFileWrapper::getId(const Ice::Current&)
44 {
45  return gridFile->getFileField("_id").OID().toString();
46 }
47 
48 std::string GridFileWrapper::getFilename(const Ice::Current&)
49 {
50  return gridFile->getFilename();
51 }
52 
53 std::string GridFileWrapper::getMD5(const Ice::Current&)
54 {
55  return gridFile->getMD5();
56 }
57 
59 {
60  return gridFile->getContentLength();
61 }
62 
64 {
65  return gridFile->getUploadDate();
66 }
67 
69  const Ice::Current&)
70 {
72  // this mutex was needed to avoid crashes when multiple clients access GridFS
73  std::unique_lock l(*accessGridFSFilesMutex);
74  try
75  {
76 
77  if (nextChunkNo < gridFile->getNumChunks())
78  {
79  mongo::GridFSChunk chunk = gridFile->getChunk(nextChunkNo++);
80  int datalen = 0;
81  const char* data = chunk.data(datalen);
82  buffer.resize(datalen);
83  memcpy(buffer.data(), data, datalen);
84  return datalen;
85  }
86  else
87  {
88  return 0;
89  }
90  }
91  catch (...)
92  {
93  ARMARX_ERROR << VAROUT(nextChunkNo) << "\n"
94  << VAROUT(gridFile) << "\n"
95  << VAROUT(gridFile->getFilename()) << "\n"
96  << VAROUT(gridFile->exists()) << "\n"
97  << VAROUT(gridFile->getChunkSize()) << "\n"
98  << VAROUT(gridFile->getNumChunks()) << "\n"
99  << VAROUT(gridFile->getContentLength()) << "\n"
100  << VAROUT(gridFile->getContentType()) << "\n"
101  << VAROUT(gridFile->getMD5()) << "\n"
102  << VAROUT(gridFile->getMetadata().jsonString()) << "\n"
104 
105  throw;
106  }
107 }
108 
110 {
111  return iceId;
112 }
113 
GridFileWrapper.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::GridFileWrapper::getIceId
Ice::Identity getIceId() const
Definition: GridFileWrapper.cpp:109
memoryx::GridFileWrapper::getFileSize
::Ice::Long getFileSize(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GridFileWrapper.cpp:58
mongo
Definition: CommonStorage.h:34
memoryx::GridFileWrapper::getUploadDate
::Ice::Long getUploadDate(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GridFileWrapper.cpp:63
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:147
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
memoryx::GridFileWrapper::getId
::std::string getId(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GridFileWrapper.cpp:43
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
memoryx::GridFileWrapper::getNextChunk
::Ice::Int getNextChunk(::memoryx::Blob &buffer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GridFileWrapper.cpp:68
memoryx::GridFileWrapper::~GridFileWrapper
~GridFileWrapper() override
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
memoryx::GridFileWrapper::getMD5
::std::string getMD5(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GridFileWrapper.cpp:53
memoryx::GridFileWrapper::GridFileWrapper
GridFileWrapper(const mongo::GridFile &gridFile, const std::shared_ptr< std::mutex > &accessGridFSFilesMutex)
Definition: GridFileWrapper.cpp:32
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::GridFileWrapper::getFilename
::std::string getFilename(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GridFileWrapper.cpp:48
Logging.h
Exception.h