Skip to content

Commit 0c27712

Browse files
Sujay Patelfacebook-github-bot
Sujay Patel
authored andcommitted
Skeleton for MoQTestClient with main method
Summary: Structure for MoqTestClient class with functions defined and main method. Reviewed By: sharmafb Differential Revision: D75456552 fbshipit-source-id: 6eea901eb94a5e0f9b0872ae9931c43e94e92ea2
1 parent 8a85ba1 commit 0c27712

File tree

3 files changed

+178
-1
lines changed

3 files changed

+178
-1
lines changed

moxygen/MoQSession.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,6 @@ folly::coro::Task<Publisher::SubscribeResult> MoQSession::subscribe(
31623162
auto subTrack = subTracks_.try_emplace(trackAlias, trackReceiveState);
31633163
XCHECK(subTrack.second) << "Track alias already in use alias=" << trackAlias
31643164
<< " sess=" << this;
3165-
31663165
auto subscribeResult = co_await trackReceiveState->subscribeFuture();
31673166
XLOG(DBG1) << "Subscribe ready trackReceiveState=" << trackReceiveState
31683167
<< " requestID=" << reqID;

moxygen/moqtest/MoQTestClient.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
#include "moxygen/moqtest/MoQTestClient.h"
4+
#include "folly/coro/BlockingWait.h"
5+
#include "folly/init/Init.h"
6+
#include "folly/io/async/ScopedEventBaseThread.h"
7+
#include "moxygen/MoQClient.h"
8+
#include "moxygen/moqtest/Utils.h"
9+
10+
namespace moxygen {
11+
12+
DEFINE_string(url, "http://localhost:9999", "URL to connect to");
13+
DEFINE_int32(connect_timeout, 1000, "connect timeout in ms");
14+
DEFINE_int32(transaction_timeout, 1000, "transaction timeout in ms");
15+
const int kDefaultRequestId = 0;
16+
const std::string kDefaultTrackName = "test";
17+
const GroupOrder kDefaultGroupOrder = GroupOrder(0x0);
18+
const LocationType kDefaultLocationType = LocationType(1);
19+
const uint64_t kDefaultEndGroup = 128;
20+
21+
MoQTestClient::MoQTestClient(folly::EventBase* evb, proxygen::URL url)
22+
: moqClient_(std::make_unique<MoQClient>(evb, std::move(url))) {}
23+
24+
folly::coro::Task<void> MoQTestClient::connect(folly::EventBase* evb) {
25+
co_await moqClient_->setupMoQSession(
26+
std::chrono::milliseconds(FLAGS_connect_timeout),
27+
std::chrono::seconds(FLAGS_transaction_timeout),
28+
nullptr,
29+
shared_from_this());
30+
co_return;
31+
}
32+
33+
void MoQTestClient::initialize() {
34+
// Create a receiver for the client
35+
subReceiver_ = std::make_shared<ObjectReceiver>(
36+
ObjectReceiver::SUBSCRIBE,
37+
std::shared_ptr<MoQTestClient>(shared_from_this()));
38+
fetchReceiver_ = std::make_shared<ObjectReceiver>(
39+
ObjectReceiver::FETCH,
40+
std::shared_ptr<MoQTestClient>(shared_from_this()));
41+
}
42+
43+
folly::coro::Task<moxygen::TrackNamespace> MoQTestClient::subscribe(
44+
MoQTestParameters params) {
45+
auto trackNamespace = convertMoqTestParamToTrackNamespace(&params);
46+
47+
// Create a SubRequest with the created TrackNamespace as its fullTrackName
48+
SubscribeRequest sub;
49+
sub.requestID = kDefaultRequestId;
50+
51+
FullTrackName ftn;
52+
ftn.trackNamespace = trackNamespace.value();
53+
ftn.trackName = kDefaultTrackName;
54+
55+
sub.fullTrackName = ftn;
56+
sub.trackAlias = TrackAlias();
57+
sub.groupOrder = kDefaultGroupOrder;
58+
sub.locType = kDefaultLocationType;
59+
sub.endGroup = kDefaultEndGroup;
60+
61+
// Subscribe to the reciever
62+
auto res = co_await moqClient_->moqSession_->subscribe(sub, subReceiver_);
63+
64+
co_return trackNamespace.value();
65+
}
66+
67+
folly::coro::Task<moxygen::TrackNamespace> MoQTestClient::fetch(
68+
MoQTestParameters params) {
69+
auto trackNamespace = convertMoqTestParamToTrackNamespace(&params);
70+
71+
// Create a Fetch with the created TrackNamespace as its fullTrackName
72+
Fetch fetch;
73+
fetch.requestID = kDefaultRequestId;
74+
75+
FullTrackName ftn;
76+
ftn.trackNamespace = trackNamespace.value();
77+
ftn.trackName = kDefaultTrackName;
78+
fetch.fullTrackName = ftn;
79+
fetch.groupOrder = kDefaultGroupOrder;
80+
81+
// Fetch to the reciever
82+
auto res = co_await moqClient_->moqSession_->fetch(fetch, fetchReceiver_);
83+
84+
co_return trackNamespace.value();
85+
}
86+
87+
ObjectReceiverCallback::FlowControlState MoQTestClient::onObject(
88+
const ObjectHeader& objHeader,
89+
Payload payload) {
90+
std::cout << "onObject" << std::endl;
91+
return ObjectReceiverCallback::FlowControlState::BLOCKED;
92+
}
93+
94+
void MoQTestClient::onObjectStatus(const ObjectHeader& objHeader) {
95+
std::cout << "onObjectStatus" << std::endl;
96+
}
97+
98+
void MoQTestClient::onEndOfStream() {
99+
std::cout << "onEndOfStream" << std::endl;
100+
}
101+
102+
void MoQTestClient::onError(ResetStreamErrorCode) {
103+
std::cout << "onError" << std::endl;
104+
}
105+
void MoQTestClient::onSubscribeDone(SubscribeDone done) {
106+
std::cout << "onSubscribeDone" << std::endl;
107+
}
108+
109+
} // namespace moxygen
110+
111+
int main(int argc, char** argv) {
112+
gflags::ParseCommandLineFlags(&argc, &argv, false);
113+
folly::Init init(&argc, &argv);
114+
115+
folly::ScopedEventBaseThread evb;
116+
117+
// Initialize Client with url
118+
moxygen::MoQTestParameters kDefaultMoqParams;
119+
auto url = proxygen::URL(moxygen::FLAGS_url);
120+
std::shared_ptr<moxygen::MoQTestClient> client =
121+
std::make_shared<moxygen::MoQTestClient>(evb.getEventBase(), url);
122+
client->initialize();
123+
124+
// Connect Client to Server
125+
folly::coro::blockingWait(
126+
client->connect(evb.getEventBase()).scheduleOn(evb.getEventBase()));
127+
128+
// Test a Subscribe Call
129+
folly::coro::blockingWait(
130+
client->subscribe(kDefaultMoqParams).scheduleOn(evb.getEventBase()));
131+
132+
sleep(10);
133+
134+
return 0;
135+
}

moxygen/moqtest/MoQTestClient.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
#pragma once
4+
5+
#include "moxygen/MoQClient.h"
6+
#include "moxygen/ObjectReceiver.h"
7+
#include "moxygen/Subscriber.h"
8+
#include "moxygen/moqtest/Types.h"
9+
10+
namespace moxygen {
11+
12+
class MoQTestClient : public moxygen::Subscriber,
13+
public std::enable_shared_from_this<MoQTestClient>,
14+
public ObjectReceiverCallback {
15+
public:
16+
MoQTestClient(folly::EventBase* evb, proxygen::URL url);
17+
18+
~MoQTestClient() override {}
19+
20+
folly::coro::Task<void> connect(folly::EventBase* evb);
21+
22+
void initialize();
23+
24+
folly::coro::Task<moxygen::TrackNamespace> subscribe(
25+
MoQTestParameters params);
26+
27+
folly::coro::Task<moxygen::TrackNamespace> fetch(MoQTestParameters params);
28+
29+
// Override Vritual Functions for now to return basic print statements
30+
virtual FlowControlState onObject(
31+
const ObjectHeader& objHeader,
32+
Payload payload) override;
33+
virtual void onObjectStatus(const ObjectHeader& objHeader) override;
34+
virtual void onEndOfStream() override;
35+
virtual void onError(ResetStreamErrorCode) override;
36+
virtual void onSubscribeDone(SubscribeDone done) override;
37+
38+
private:
39+
std::unique_ptr<MoQClient> moqClient_;
40+
std::shared_ptr<ObjectReceiver> subReceiver_;
41+
std::shared_ptr<ObjectReceiver> fetchReceiver_;
42+
};
43+
} // namespace moxygen

0 commit comments

Comments
 (0)