-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba27223
commit ba5b580
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <stdexcept> | ||
#include "LockFile.h" | ||
|
||
using namespace Aws::Iot::DeviceClient::Util; | ||
|
||
LockFile::LockFile(const std::string& filename) | ||
: filename(filename) | ||
, file(fopen(filename.c_str(), "wx")) | ||
{ | ||
if (!file) | ||
{ | ||
throw std::runtime_error{"unable to open lockfile"}; | ||
} | ||
flockfile(file); | ||
} | ||
|
||
LockFile::~LockFile() | ||
{ | ||
funlockfile(file); | ||
fclose(file); | ||
remove(filename.c_str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef AWS_IOT_DEVICE_CLIENT_LOCKFILE_H | ||
#define AWS_IOT_DEVICE_CLIENT_LOCKFILE_H | ||
|
||
#include <string> | ||
|
||
namespace Aws | ||
{ | ||
namespace Iot | ||
{ | ||
namespace DeviceClient | ||
{ | ||
namespace Util | ||
{ | ||
struct LockFile | ||
{ | ||
private: | ||
static constexpr char TAG[] = "LockFile.cpp"; | ||
std::string filename; | ||
FILE *file{nullptr}; | ||
|
||
public: | ||
LockFile(const std::string& filename); | ||
~LockFile(); | ||
|
||
// Non-copyable. | ||
LockFile(const LockFile &) = delete; | ||
LockFile &operator=(const LockFile &) = delete; | ||
}; | ||
} // namespace Util | ||
} // namespace DeviceClient | ||
} // namespace Iot | ||
} // namespace Aws | ||
|
||
#endif // AWS_IOT_DEVICE_CLIENT_LOCKFILE_H |