Skip to content

Commit bb1c676

Browse files
committed
add cmake options to disable a special feature.
1 parent 1278acb commit bb1c676

36 files changed

+530
-342
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ cmake .. -DBUILD_TESTS=ON
116116
cmake .. -DENABLE_RTTI=OFF
117117
```
118118

119+
#### OSS_DISABLE_BUCKET
120+
(Default OFF) If turned ON, the SDK is built without the bucket's API.
121+
```
122+
cmake .. -DOSS_DISABLE_BUCKET=ON
123+
```
124+
#### OSS_DISABLE_LIVECHANNEL
125+
(Default OFF) If turned ON, the SDK is built without the livechannel's API.
126+
```
127+
cmake .. -DOSS_DISABLE_LIVECHANNEL=ON
128+
```
129+
130+
#### OSS_DISABLE_RESUAMABLE
131+
(Default OFF) If turned ON, the SDK is built without the resumable operation feature.
132+
```
133+
cmake .. -DOSS_DISABLE_RESUAMABLE=ON
134+
```
135+
136+
#### OSS_DISABLE_ENCRYPTION
137+
(Default OFF) If turned ON, the SDK is built without the client-side encryption feature.
138+
```
139+
cmake .. -DOSS_DISABLE_ENCRYPTION=ON
140+
```
141+
119142
## Use the C++ SDK
120143

121144
The following code shows how to list buckets owned by the requester.

README_zh.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ cmake .. -DBUILD_TESTS=ON
116116
cmake .. -DENABLE_RTTI=OFF
117117
```
118118

119+
#### OSS_DISABLE_BUCKET
120+
(默认为关,即OFF) 如果打开, 构建的库不会包含和 bucket 有关的接口.
121+
```
122+
cmake .. -DOSS_DISABLE_BUCKET=ON
123+
```
124+
#### OSS_DISABLE_LIVECHANNEL
125+
(默认为关,即OFF) 如果打开, 构建的库不会包含和 livechannel 有关的接口.
126+
```
127+
cmake .. -DOSS_DISABLE_LIVECHANNEL=ON
128+
```
129+
130+
#### OSS_DISABLE_RESUAMABLE
131+
(默认为关,即OFF) 如果打开, 构建的库不会包含断点续传功能.
132+
```
133+
cmake .. -DOSS_DISABLE_RESUAMABLE=ON
134+
```
135+
136+
#### OSS_DISABLE_ENCRYPTION
137+
(默认为关,即OFF) 如果打开, 构建的库不会包含客户端加密功能.
138+
```
139+
cmake .. -DOSS_DISABLE_ENCRYPTION=ON
140+
```
141+
119142
## 如何使用 C++ SDK
120143

121144
以下代码展示了如何获取请求者拥有的Bucket。

sample/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@
1616
project(cpp-sdk-sample VERSION ${version})
1717

1818
file(GLOB sample_src "src/*")
19+
20+
if (NOT OSS_DISABLE_BUCKET)
1921
file(GLOB sample_service_src "src/service/*")
2022
file(GLOB sample_bucket_src "src/bucket/*")
23+
endif()
24+
2125
file(GLOB sample_object_src "src/object/*")
2226
file(GLOB sample_presignedurl_src "src/presignedurl/*")
27+
28+
if (NOT OSS_DISABLE_LIVECHANNEL)
2329
file(GLOB sample_livechannel_src "src/LiveChannel/*")
24-
file(GLOB sample_encryption_src "src/encryption/*")
30+
endif()
2531

32+
if (NOT OSS_DISABLE_ENCRYPTION)
33+
file(GLOB sample_encryption_src "src/encryption/*")
34+
endif()
2635

2736
add_executable(${PROJECT_NAME}
2837
${sample_src}

sample/src/LiveChannel/LiveChannelSample.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,14 @@ static void waitTimeinSec(int time)
2323
LiveChannelSample::LiveChannelSample(const std::string& bucket, const std::string& channelName):bucket_(bucket),channelName_(channelName),
2424
timeStart_(0),timeEnd_(0),isSuccess_(false)
2525
{
26-
2726
ClientConfiguration conf;
2827
client = new OssClient(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, conf);
29-
CreateBucketRequest request(bucket_);
30-
client->CreateBucket(request);
28+
//CreateBucketRequest request(bucket_);
29+
//client->CreateBucket(request);
3130
}
3231

3332
LiveChannelSample::~LiveChannelSample()
3433
{
35-
DeleteBucketRequest request(bucket_);
36-
auto deleteOutcome = client->DeleteBucket(request);
37-
38-
if(!deleteOutcome.isSuccess())
39-
{
40-
std::cerr<<"delete bucket "+bucket_+" fail";
41-
}
42-
4334
if(nullptr != client)
4435
{
4536
delete client;

sample/src/Program.cc

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#include <alibabacloud/oss/OssClient.h>
22
#include <iostream>
33
#include "Config.h"
4+
5+
#if !defined(OSS_DISABLE_BUCKET)
46
#include "service/ServiceSample.h"
57
#include "bucket/BucketSample.h"
8+
#endif
9+
610
#include "object/ObjectSample.h"
711
#include "presignedurl/PresignedUrlSample.h"
12+
13+
#if !defined(OSS_DISABLE_LIVECHANNEL)
814
#include "LiveChannel/LiveChannelSample.h"
9-
#include "encryption/EncryptionSample.h"
15+
#endif
1016

17+
#if !defined(OSS_DISABLE_ENCRYPTION)
18+
#include "encryption/EncryptionSample.h"
19+
#endif
1120

1221
using namespace AlibabaCloud::OSS;
1322

@@ -29,6 +38,7 @@ int main(void)
2938
SetLogLevel(LogLevel::LogDebug);
3039
SetLogCallback(LogCallbackFunc);
3140

41+
#if !defined(OSS_DISABLE_BUCKET)
3242
ServiceSample serviceSample;
3343
serviceSample.ListBuckets();
3444
serviceSample.ListBucketsWithMarker();
@@ -50,11 +60,6 @@ int main(void)
5060
bucketSample.DeleteBucketLifecycle();
5161
bucketSample.DeleteBucketCors();
5262

53-
54-
bucketSample.ListObjects();
55-
bucketSample.ListObjectWithMarker();
56-
bucketSample.ListObjectWithEncodeType();
57-
5863
bucketSample.GetBucketAcl();
5964
bucketSample.GetBucketLocation();
6065
bucketSample.GetBucketLogging();
@@ -63,12 +68,9 @@ int main(void)
6368
bucketSample.GetBucketStat();
6469
bucketSample.GetBucketLifecycle();
6570
//bucketSample.DeleteBucketsByPrefix();
66-
71+
#endif
6772

6873
ObjectSample objectSample(bucketName);
69-
objectSample.UploadObjectProgress();
70-
objectSample.MultiCopyObjectProcess();
71-
objectSample.DownloadObjectProcess();
7274
objectSample.PutObjectFromBuffer();
7375
objectSample.PutObjectFromFile();
7476
objectSample.GetObjectToBuffer();
@@ -85,13 +87,25 @@ int main(void)
8587
objectSample.CopyObject();
8688
//objectSample.RestoreArchiveObject("your-archive", "oss_archive_object.PNG", 1);
8789

90+
objectSample.ListObjects();
91+
objectSample.ListObjectWithMarker();
92+
objectSample.ListObjectWithEncodeType();
93+
94+
#if !defined(OSS_DISABLE_RESUAMABLE)
95+
objectSample.UploadObjectProgress();
96+
objectSample.MultiCopyObjectProcess();
97+
objectSample.DownloadObjectProcess();
98+
#endif
99+
88100
PresignedUrlSample signedUrlSample(bucketName);
89101
signedUrlSample.GenGetPresignedUrl();
90102
signedUrlSample.PutObjectByUrlFromBuffer();
91103
signedUrlSample.PutObjectByUrlFromFile();
92104
signedUrlSample.GetObjectByUrlToBuffer();
93105
signedUrlSample.GetObjectByUrlToFile();
94106

107+
108+
#if !defined(OSS_DISABLE_LIVECHANNEL)
95109
// LiveChannel
96110
LiveChannelSample liveChannelSample(bucketName, "test_channel");
97111
liveChannelSample.PutLiveChannel();
@@ -103,16 +117,21 @@ int main(void)
103117
liveChannelSample.GetVodPlayList();
104118
liveChannelSample.PutLiveChannelStatus();
105119
liveChannelSample.DeleteLiveChannel();
120+
#endif
106121

122+
#if !defined(OSS_DISABLE_ENCRYPTION)
107123
// Encryption
108124
EncryptionSample encryptionSample(bucketName);
109125
encryptionSample.PutObjectFromBuffer();
110126
encryptionSample.PutObjectFromFile();
111127
encryptionSample.GetObjectToBuffer();
112128
encryptionSample.GetObjectToFile();
129+
#if !defined(DISABLE_RESUAMABLE)
113130
encryptionSample.UploadObjectProgress();
114131
encryptionSample.DownloadObjectProcess();
115132
encryptionSample.MultipartUploadObject();
133+
#endif
134+
#endif
116135

117136
ShutdownSdk();
118137
return 0;

sample/src/bucket/BucketSample.cc

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -258,75 +258,6 @@ void BucketSample::DeleteBucketCors()
258258
}
259259
}
260260

261-
void BucketSample::ListObjects()
262-
{
263-
ListObjectsRequest request(bucket_);
264-
auto outcome = client->ListObjects(request);
265-
if (outcome.isSuccess()) {
266-
std::cout << __FUNCTION__ << " success " <<
267-
"and object count is " << outcome.result().ObjectSummarys().size() << std::endl;
268-
}
269-
else {
270-
PrintError(__FUNCTION__, outcome.error());
271-
}
272-
}
273-
274-
void BucketSample::ListObjectWithMarker()
275-
{
276-
ListObjectsRequest request(bucket_);
277-
request.setMaxKeys(1);
278-
bool IsTruncated = false;
279-
size_t total = 0;
280-
do {
281-
auto outcome = client->ListObjects(request);
282-
283-
if (outcome.isSuccess()) {
284-
std::cout << __FUNCTION__ << " success, " <<
285-
"and object count is " << outcome.result().ObjectSummarys().size() <<
286-
"next marker is " << outcome.result().NextMarker() << std::endl;
287-
total += outcome.result().ObjectSummarys().size();
288-
}
289-
else {
290-
PrintError(__FUNCTION__, outcome.error());
291-
break;
292-
}
293-
294-
request.setMarker(outcome.result().NextMarker());
295-
IsTruncated = outcome.result().IsTruncated();
296-
} while (IsTruncated);
297-
298-
std::cout << __FUNCTION__ << " done, and total is " << total << std::endl;
299-
}
300-
301-
void BucketSample::ListObjectWithEncodeType()
302-
{
303-
ListObjectsRequest request(bucket_);
304-
request.setEncodingType("url");
305-
bool IsTruncated = false;
306-
size_t total = 0;
307-
request.setMaxKeys(1);
308-
ListObjectOutcome outcome;
309-
do {
310-
outcome = client->ListObjects(request);
311-
312-
if (outcome.isSuccess()) {
313-
std::cout << __FUNCTION__ << " success, " <<
314-
"and object count is " << outcome.result().ObjectSummarys().size() <<
315-
"next marker is " << outcome.result().NextMarker() << std::endl;
316-
total += outcome.result().ObjectSummarys().size();
317-
}
318-
else {
319-
PrintError(__FUNCTION__, outcome.error());
320-
break;
321-
}
322-
323-
request.setMarker(outcome.result().NextMarker());
324-
IsTruncated = outcome.result().IsTruncated();
325-
} while (IsTruncated);
326-
327-
std::cout << __FUNCTION__ << " done, and total is " << total << std::endl;
328-
}
329-
330261
void BucketSample::GetBucketAcl()
331262
{
332263
GetBucketAclRequest request(bucket_);

sample/src/bucket/BucketSample.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ class BucketSample
2222
void DeleteBucketLifecycle();
2323
void DeleteBucketCors();
2424

25-
void ListObjects();
26-
void ListObjectWithMarker();
27-
void ListObjectWithEncodeType();
28-
2925
void GetBucketAcl();
3026
void GetBucketLocation();
3127
void GetBucketLogging();

sample/src/encryption/EncryptionSample.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ EncryptionSample::EncryptionSample(const std::string &bucket) :
3636
auto materials = std::make_shared<SimpleRSAEncryptionMaterials>(publicKey, privateKey);
3737
client = new OssEncryptionClient(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret,
3838
conf, materials, cryptoConf);
39-
CreateBucketRequest request(bucket_);
39+
//CreateBucketRequest request(bucket_);
4040
}
4141

4242
EncryptionSample::~EncryptionSample() {
@@ -109,6 +109,7 @@ static void ProgressCallback(size_t increment, int64_t transfered, int64_t total
109109
increment <<" ," << transfered << "," << total << std::endl;
110110
}
111111

112+
#if !defined(DISABLE_RESUAMABLE)
112113
void EncryptionSample::UploadObjectProgress()
113114
{
114115
//case 1: checkpoint dir is not enabled
@@ -204,6 +205,7 @@ void EncryptionSample::DownloadObjectProcess()
204205
}
205206
}
206207
}
208+
#endif
207209

208210
void EncryptionSample::MultipartUploadObject()
209211
{

sample/src/encryption/EncryptionSample.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ class EncryptionSample
1010
void PutObjectFromFile();
1111
void GetObjectToBuffer();
1212
void GetObjectToFile();
13+
void MultipartUploadObject();
14+
15+
#if !defined(OSS_DISABLE_RESUAMABLE)
1316
void UploadObjectProgress();
1417
void DownloadObjectProcess();
15-
void MultipartUploadObject();
18+
#endif
1619

1720
private:
1821
void PrintError(const std::string &funcName, const AlibabaCloud::OSS::OssError &error);

0 commit comments

Comments
 (0)