Debian Codegraph @

Xpjproject/pjsip/src/pjsua2-test/instant_messaging.hpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2025 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifndef INSTANT_MESSAGING_TESTS_HPP
20 #define INSTANT_MESSAGING_TESTS_HPP
21
22 #include <pjsua2.hpp>
23 #include <memory>
24
25 using namespace pj;
26
27 /**
28 * Account that receives SIP MESSAGE and defers the response
29 */
30 class ReceiverAccount : public Account
31 {
32 private:
33 DeferredResponse deferredResponse;
34
35 public:
36 ReceiverAccount();
37 virtual ~ReceiverAccount();
38
39 /**
40 * Override onInstantMessage to store deferred response
41 */
42 virtual void onInstantMessage(OnInstantMessageParam &prm) override;
43
44 /**
45 * Send deferred response with specified status code and reason
46 */
47 void sendDeferredResponse(int statusCode, const std::string& reason);
48 };
49
50 /**
51 * Account that sends SIP MESSAGE to the receiver account
52 */
53 class SenderAccount : public Account
54 {
55 public:
56 using Account::Account;
57
58 /**
59 * Override onInstantMessageStatus to track response reception
60 */
61 virtual
62 void onInstantMessageStatus(OnInstantMessageStatusParam &prm) override;
63 };
64
65 /**
66 * Structure to hold test state information
67 */
68 struct TestState {
69 bool messageReceived = false;
70 bool responseSent = false;
71 bool responseReceived = false;
72 int responseStatusCode = 0;
73 std::string receivedMessage{};
74 std::string responseReason{};
75 };
76
77 /**
78 * Test class for deferred SIP MESSAGE response functionality
79 */
80 class InstantMessagingTests
81 {
82 static TestState testState;
83 friend class ReceiverAccount;
84 friend class SenderAccount;
85
86 public:
87 InstantMessagingTests();
88 InstantMessagingTests(const InstantMessagingTests&) = delete;
89 InstantMessagingTests& operator=(const InstantMessagingTests&) = delete;
90 InstantMessagingTests(InstantMessagingTests&&) = delete;
91 InstantMessagingTests& operator=(InstantMessagingTests&&) = delete;
92 ~InstantMessagingTests();
93
94 void immediateResponse();
95 void deferredResponse();
96 private:
97 Endpoint ep;
98 std::unique_ptr<ReceiverAccount> receiverAcc;
99 std::unique_ptr<SenderAccount> senderAcc;
100 std::unique_ptr<Buddy> senderBuddy;
101 };
102
103 #endif // INSTANT_MESSAGING_TESTS_HPP