Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / include / WrapperFactory.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OC_WRAPPER_FACTORY_H_
22 #define OC_WRAPPER_FACTORY_H_
23
24 #include <memory>
25 #include <OCApi.h>
26 #include "IClientWrapper.h"
27 #include "IServerWrapper.h"
28 #include <OutOfProcClientWrapper.h>
29 #include <InProcClientWrapper.h>
30 #include <OutOfProcServerWrapper.h>
31 #include <InProcServerWrapper.h>
32 #include "StringConstants.h"
33
34 namespace OC
35 {
36     // Interface to permit easier mocking/unit testing later
37     class IWrapperFactory
38     {
39     public:
40         typedef std::shared_ptr<IWrapperFactory> Ptr;
41
42         virtual IClientWrapper::Ptr CreateClientWrapper(
43             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg) =0;
44         virtual IServerWrapper::Ptr CreateServerWrapper(
45             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg) =0;
46         virtual ~IWrapperFactory(){}
47     };
48
49     // Class to create the client/server object!
50     class WrapperFactory : public IWrapperFactory
51     {
52     public:
53         WrapperFactory(){}
54
55         virtual IClientWrapper::Ptr CreateClientWrapper(
56             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
57         {
58             switch(cfg.serviceType)
59             {
60             case ServiceType::InProc:
61                 return std::make_shared<InProcClientWrapper>(csdkLock, cfg);
62                 break;
63             case ServiceType::OutOfProc:
64                 return std::make_shared<OutOfProcClientWrapper>(csdkLock, cfg);
65                 break;
66             }
67                         return nullptr;
68         }
69
70         virtual IServerWrapper::Ptr CreateServerWrapper(
71             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
72         {
73             switch(cfg.serviceType)
74             {
75             case ServiceType::InProc:
76                 return std::make_shared<InProcServerWrapper>(csdkLock, cfg);
77                 break;
78             case ServiceType::OutOfProc:
79                 throw OC::OCException(OC::Exception::SVCTYPE_OUTOFPROC, OC_STACK_NOTIMPL);
80                 break;
81             }
82                         return nullptr;
83         }
84
85         virtual ~WrapperFactory(){}
86     };
87 }
88
89 #endif