summaryrefslogtreecommitdiff
path: root/src/framework/client/handle.h
blob: 8f2625cbd304f239d7f5c6685126678962af3054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License
 */
/*
 * @file        handle.h
 * @author      Kyungwook Tak (k.tak@samsung.com)
 * @version     1.0
 * @brief       Client request handle with dispatcher in it
 */
#pragma once

#include <utility>
#include <memory>
#include <vector>

#include "common/icontext.h"
#include "common/dispatcher.h"
#include "common/socket-descriptor.h"

namespace Csr {
namespace Client {

class Handle {
public:
	explicit Handle(SockId, ContextShPtr &&);
	explicit Handle(SockId);
	virtual ~Handle();

	template<typename Type, typename ...Args>
	Type dispatch(Args &&...);

	virtual void add(ResultPtr &&);
	virtual void add(ResultListPtr &&);

	ContextShPtr &getContext(void) noexcept;

protected:
	// for destroying with context
	std::vector<ResultPtr> m_results;
	std::vector<ResultListPtr> m_resultLists;

private:
	SockId m_sockId;
	std::unique_ptr<Dispatcher> m_dispatcher;
	ContextShPtr m_ctx;
};

template<typename Type, typename ...Args>
Type Handle::dispatch(Args &&...args)
{
	if (m_dispatcher == nullptr)
		m_dispatcher.reset(new Dispatcher(m_sockId));

	return m_dispatcher->methodCall<Type>(std::forward<Args>(args)...);
}

} // namespace Client
} // namespace Csr