1/*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
8#ifndef _COPY_ENGINE_H
9#define _COPY_ENGINE_H
10
11
12#include <stdarg.h>
13
14#include <EntryOperationEngineBase.h>
15
16
17class BFile;
18class BNode;
19
20
21namespace BPrivate {
22
23
24class BCopyEngine : public BEntryOperationEngineBase {
25public:
26			class BController;
27
28			enum {
29				COPY_RECURSIVELY			= 0x01,
30				MERGE_EXISTING_DIRECTORIES	= 0x02,
31				UNLINK_DESTINATION			= 0x04,
32			};
33
34public:
35								BCopyEngine(uint32 flags = 0);
36								~BCopyEngine();
37
38			BController*		Controller() const;
39			void				SetController(BController* controller);
40
41			uint32				Flags() const;
42			BCopyEngine&		SetFlags(uint32 flags);
43			BCopyEngine&		AddFlags(uint32 flags);
44			BCopyEngine&		RemoveFlags(uint32 flags);
45
46			status_t			CopyEntry(const Entry& sourceEntry,
47									const Entry& destEntry);
48
49private:
50			status_t			_CopyEntry(const char* sourcePath,
51									const char* destPath);
52			status_t			_CopyFileData(const char* sourcePath,
53									BFile& source, const char* destPath,
54									BFile& destination);
55			status_t			_CopyAttributes(const char* sourcePath,
56									BNode& source, const char* destPath,
57									BNode& destination);
58
59			void				_NotifyError(status_t error, const char* format,
60									...);
61			void				_NotifyErrorVarArgs(status_t error,
62									const char* format, va_list args);
63			status_t			_HandleEntryError(const char* path,
64									status_t error, const char* format, ...);
65			status_t			_HandleAttributeError(const char* path,
66									const char* attribute, uint32 attributeType,
67									status_t error, const char* format, ...);
68
69private:
70			BController*		fController;
71			uint32				fFlags;
72			char*				fBuffer;
73			size_t				fBufferSize;
74};
75
76
77class BCopyEngine::BController {
78public:
79								BController();
80	virtual						~BController();
81
82	virtual	bool				EntryStarted(const char* path);
83	virtual	bool				EntryFinished(const char* path, status_t error);
84
85	virtual	bool				AttributeStarted(const char* path,
86									const char* attribute,
87									uint32 attributeType);
88	virtual	bool				AttributeFinished(const char* path,
89									const char* attribute,
90									uint32 attributeType, status_t error);
91
92	virtual	void				ErrorOccurred(const char* message,
93									status_t error);
94};
95
96
97} // namespace BPrivate
98
99
100using ::BPrivate::BCopyEngine;
101
102
103#endif	// _COPY_ENGINE_H
104