Add first version
[ric-plt/sdl.git] / src / redis / asynccommanddispatcher.cpp
1 /*
2    Copyright (c) 2018-2019 Nokia.
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 */
16
17 #include "private/redis/asynccommanddispatcher.hpp"
18 #include <cstdlib>
19 #include "config.h"
20 #include "private/redis/databaseinfo.hpp"
21 #if HAVE_HIREDIS_VIP
22 #include "private/redis/asynchiredisclustercommanddispatcher.hpp"
23 #include "private/redis/asynchirediscommanddispatcher.hpp"
24 #elif HAVE_HIREDIS
25 #include "private/redis/asynchirediscommanddispatcher.hpp"
26 #endif
27 #include "private/abort.hpp"
28 #include "private/engine.hpp"
29
30 using namespace shareddatalayer::redis;
31
32 std::shared_ptr<AsyncCommandDispatcher> AsyncCommandDispatcher::create(Engine& engine,
33                                                                        const DatabaseInfo& databaseInfo,
34                                                                        std::shared_ptr<ContentsBuilder> contentsBuilder,
35                                                                        bool usePermanentCommandCallbacks,
36                                                                        std::shared_ptr<Logger> logger)
37 {
38 #if HAVE_HIREDIS_VIP
39     if (databaseInfo.type == DatabaseInfo::Type::CLUSTER)
40     {
41         return std::make_shared<AsyncHiredisClusterCommandDispatcher>(engine,
42                                                                       databaseInfo.ns,
43                                                                       databaseInfo.hosts,
44                                                                       contentsBuilder,
45                                                                       usePermanentCommandCallbacks,
46                                                                       logger);
47     }
48     else
49         return std::make_shared<AsyncHiredisCommandDispatcher>(engine,
50                                                                databaseInfo.hosts.at(0).getHost(),
51                                                                databaseInfo.hosts.at(0).getPort(),
52                                                                contentsBuilder,
53                                                                usePermanentCommandCallbacks,
54                                                                logger);
55 #elif HAVE_HIREDIS
56     if (databaseInfo.type == DatabaseInfo::Type::CLUSTER)
57         SHAREDDATALAYER_ABORT("Not implemented.");
58     return std::make_shared<AsyncHiredisCommandDispatcher>(engine,
59                                                            databaseInfo.hosts.at(0).getHost(),
60                                                            databaseInfo.hosts.at(0).getPort(),
61                                                            contentsBuilder,
62                                                            usePermanentCommandCallbacks,
63                                                            logger);
64 #else
65     SHAREDDATALAYER_ABORT("Not implemented.");
66 #endif
67 }