2012-01-10 16:50:14 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef BIN_DIRECTORY_H_
|
|
|
|
#define BIN_DIRECTORY_H_
|
|
|
|
|
|
|
|
#include "bin/builtin.h"
|
2012-02-21 11:35:42 +00:00
|
|
|
#include "bin/dartutils.h"
|
2012-01-06 11:28:21 +00:00
|
|
|
#include "platform/globals.h"
|
2012-03-01 14:29:12 +00:00
|
|
|
#include "platform/thread.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2012-02-21 11:35:42 +00:00
|
|
|
class DirectoryListing {
|
|
|
|
public:
|
|
|
|
enum Response {
|
|
|
|
kListDirectory = 0,
|
|
|
|
kListFile = 1,
|
|
|
|
kListError = 2,
|
|
|
|
kListDone = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit DirectoryListing(Dart_Port response_port)
|
|
|
|
: response_port_(response_port) {}
|
|
|
|
bool HandleDirectory(char* dir_name);
|
|
|
|
bool HandleFile(char* file_name);
|
2012-03-27 08:50:35 +00:00
|
|
|
bool HandleError(const char* dir_name);
|
2012-02-21 11:35:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CObjectArray* NewResponse(Response response, char* arg);
|
|
|
|
Dart_Port response_port_;
|
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(DirectoryListing);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
class Directory {
|
|
|
|
public:
|
2011-10-14 12:42:44 +00:00
|
|
|
enum ExistsResult {
|
|
|
|
UNKNOWN,
|
|
|
|
EXISTS,
|
|
|
|
DOES_NOT_EXIST
|
|
|
|
};
|
|
|
|
|
2012-05-22 12:46:25 +00:00
|
|
|
// This enum must be kept in sync with the request values in
|
|
|
|
// directory_impl.dart.
|
2012-02-21 11:35:42 +00:00
|
|
|
enum DirectoryRequest {
|
|
|
|
kCreateRequest = 0,
|
|
|
|
kDeleteRequest = 1,
|
|
|
|
kExistsRequest = 2,
|
|
|
|
kCreateTempRequest = 3,
|
2012-05-22 12:46:25 +00:00
|
|
|
kListRequest = 4,
|
|
|
|
kRenameRequest = 5
|
2012-02-21 11:35:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool List(const char* path,
|
2011-10-05 05:20:07 +00:00
|
|
|
bool recursive,
|
2012-02-21 11:35:42 +00:00
|
|
|
DirectoryListing* listing);
|
2011-10-14 12:42:44 +00:00
|
|
|
static ExistsResult Exists(const char* path);
|
2012-03-07 13:23:08 +00:00
|
|
|
static char* Current();
|
2011-10-14 12:42:44 +00:00
|
|
|
static bool Create(const char* path);
|
2012-03-13 13:00:47 +00:00
|
|
|
static char* CreateTemp(const char* const_template);
|
2012-02-03 12:37:30 +00:00
|
|
|
static bool Delete(const char* path, bool recursive);
|
2012-05-22 12:46:25 +00:00
|
|
|
static bool Rename(const char* path, const char* new_path);
|
2012-03-01 14:29:12 +00:00
|
|
|
static Dart_Port GetServicePort();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static dart::Mutex mutex_;
|
|
|
|
static int service_ports_size_;
|
|
|
|
static Dart_Port* service_ports_;
|
|
|
|
static int service_ports_index_;
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
DISALLOW_ALLOCATION();
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Directory);
|
|
|
|
};
|
|
|
|
|
2012-02-21 11:35:42 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
#endif // BIN_DIRECTORY_H_
|