filecopy.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef FILECOPY_HPP
  14. #define FILECOPY_HPP
  15. #include "jsocket.hpp"
  16. #include "dafdesc.hpp"
  17. #include "daft.hpp"
  18. #include "junicode.hpp"
  19. typedef enum
  20. {
  21. FFTunknown,
  22. FFTfixed, FFTvariable, FFTblocked,
  23. FFTcsv,
  24. FFTutf, // any format, default to utf-8n
  25. FFTutf8, FFTutf8n,
  26. FFTutf16, FFTutf16be, FFTutf16le,
  27. FFTutf32, FFTutf32be, FFTutf32le,
  28. FFTrecfmvb, FFTrecfmv, FFTvariablebigendian,
  29. FFTlast
  30. } FileFormatType;
  31. constexpr const char * FileFormatTypeStr[] =
  32. { "FFTunknown",
  33. "FFTfixed", "FFTvariable", "FFTblocked",
  34. "FFTcsv",
  35. "FFTutf", // any format, default to utf-8n
  36. "FFTutf8", "FFTutf8n",
  37. "FFTutf16", "FFTutf16be", "FFTutf16le",
  38. "FFTutf32", "FFTutf32be", "FFTutf32le",
  39. "FFTrecfmvb", "FFTrecfmv", "FFTvariablebigendian",
  40. "FFTlast"
  41. };
  42. enum { FTactionpull, FTactionpush, FTactionpartition, FTactiondirectory, FTactionsize, FTactionpcopy };
  43. typedef enum
  44. {
  45. FMTunknown,
  46. FMTxml,
  47. FMTjson,
  48. FMTlast
  49. } FileMarkupType;
  50. constexpr const char * FileMarkupTypeStr[] =
  51. {
  52. "FMTunknown",
  53. "FMTxml",
  54. "FMTjson",
  55. "FMTlast"
  56. };
  57. #define EFX_BLOCK_SIZE 32768
  58. class DALIFT_API FileFormat
  59. {
  60. public:
  61. FileFormat(FileFormatType _type = FFTunknown, unsigned _recordSize = 0) : markup(FMTunknown), headerLength((unsigned)-1), footerLength((unsigned)-1)
  62. { set(_type, _recordSize); maxRecordSize = 0; quotedTerminator = true;}
  63. void deserialize(MemoryBuffer & in);
  64. void deserializeExtra(MemoryBuffer & in, unsigned version);
  65. bool equals(const FileFormat & other) const { return (type == other.type) && (recordSize == other.recordSize); }
  66. unsigned getUnitSize() const;
  67. bool isUtf() const { return (type >= FFTutf) && (type <= FFTutf32le); }
  68. bool restore(IPropertyTree * props);
  69. void save(IPropertyTree * props);
  70. void serialize(MemoryBuffer & out) const;
  71. void serializeExtra(MemoryBuffer & out, unsigned version) const;
  72. void set(FileFormatType _type, unsigned _recordSize = 0) { type = _type, recordSize = _recordSize; }
  73. void set(const FileFormat & src);
  74. bool hasQuote() const { return (quote == NULL) || (*quote != '\0'); }
  75. bool hasQuotedTerminator() const { return quotedTerminator; }
  76. const char * getFileFormatTypeString() const { return FileFormatTypeStr[type]; }
  77. void updateMarkupType(const char *rowLocator, const char *kind);
  78. const char *getPartSeparatorString(){return (markup==FMTjson) ? ",\n" : NULL;}
  79. bool isCsv() const { return (type == FFTcsv); }
  80. public:
  81. FileFormatType type;
  82. unsigned recordSize;
  83. unsigned maxRecordSize;
  84. StringAttr separate;
  85. StringAttr quote;
  86. StringAttr terminate;
  87. StringAttr escape;
  88. StringAttr rowTag;
  89. //These values aren't serialized/deserialized:
  90. FileMarkupType markup;
  91. unsigned headerLength;
  92. unsigned footerLength;
  93. bool quotedTerminator;
  94. };
  95. UtfReader::UtfFormat getUtfFormatType(FileFormatType type);
  96. bool sameEncoding(const FileFormat & src, const FileFormat & tgt);
  97. typedef enum {
  98. dfu_unknown,
  99. dfu_copy,
  100. dfu_export,
  101. dfu_import,
  102. dfu_move,
  103. dfu_replicate_distributed,
  104. dfu_replicate,
  105. dfu_transfer,
  106. } dfu_operation;
  107. constexpr const char * DfuOperationStr[] =
  108. {
  109. "DFUunknown",
  110. "DFUcopy",
  111. "DFUexport",
  112. "DFUimport",
  113. "DFUmove",
  114. "DFUreplicate_distributed",
  115. "DFUreplicate",
  116. "DFUtransfer"
  117. };
  118. interface IFileSprayer : public IInterface
  119. {
  120. public:
  121. virtual void removeSource() = 0;
  122. virtual void setAbort(IAbortRequestCallback * _abort) = 0;
  123. virtual void setPartFilter(IDFPartFilter * _filter) = 0;
  124. virtual void setProgress(IDaftProgress * _progress) = 0;
  125. virtual void setReplicate(bool _replicate) = 0;
  126. virtual void setSource(IDistributedFile * source) = 0;
  127. virtual void setSource(IFileDescriptor * source) = 0;
  128. virtual void setSource(IDistributedFilePart * part) = 0;
  129. virtual void setSourceTarget(IFileDescriptor * fd, DaftReplicateMode mode) = 0;
  130. virtual void setTarget(IDistributedFile * target) = 0;
  131. virtual void setTarget(IFileDescriptor * target, unsigned copy=0) = 0;
  132. virtual void setTarget(IGroup * target) = 0;
  133. virtual void setTarget(INode * target) = 0;
  134. virtual void spray() = 0;
  135. virtual void setOperation(dfu_operation op) = 0;
  136. virtual dfu_operation getOperation() const = 0;
  137. virtual const char * getOperationTypeString() const = 0;
  138. };
  139. extern DALIFT_API IFileSprayer * createFileSprayer(IPropertyTree * _options, IPropertyTree * _progress, IRemoteConnection * recoveryConnection, const char *wuid);
  140. extern DALIFT_API void testPartitions();
  141. #endif