Merge "Patch 1 : Adding Arduino WiFi support. This requires updated Arduino WiFi...
[platform/upstream/iotivity.git] / 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 _WRAPPER_FACTORY_H_
22 #define _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
33 namespace OC
34 {
35     // Interface to permit easier mocking/unit testing later
36     class IWrapperFactory
37     {
38     public:
39         typedef std::shared_ptr<IWrapperFactory> Ptr;
40
41         virtual IClientWrapper::Ptr CreateClientWrapper(std::weak_ptr<std::mutex> csdkLock, PlatformConfig cfg) =0;
42         virtual IServerWrapper::Ptr CreateServerWrapper(std::weak_ptr<std::mutex> csdkLock, PlatformConfig cfg) =0;
43         virtual ~IWrapperFactory(){}
44     };
45
46     // Class to create the client/server object!
47     class WrapperFactory : public IWrapperFactory
48     {
49     public:
50         WrapperFactory(){}
51
52         virtual IClientWrapper::Ptr CreateClientWrapper(std::weak_ptr<std::mutex> csdkLock, PlatformConfig cfg)
53         {
54             switch(cfg.serviceType)
55             {
56             case ServiceType::InProc:
57                 return std::make_shared<InProcClientWrapper>(csdkLock, cfg);
58                 break;
59             case ServiceType::OutOfProc:
60                 return std::make_shared<OutOfProcClientWrapper>(csdkLock, cfg);
61                 break;
62             }
63                         return nullptr;
64         }
65
66         virtual IServerWrapper::Ptr CreateServerWrapper(std::weak_ptr<std::mutex> csdkLock, PlatformConfig cfg)
67         {
68             switch(cfg.serviceType)
69             {
70             case ServiceType::InProc:
71                 return std::make_shared<InProcServerWrapper>(csdkLock, cfg);
72                 break;
73             case ServiceType::OutOfProc:
74               //  return std::make_shared<OutOfProcServerWrapper>(csdkLock, cfg);
75                 break;
76             }
77                         return nullptr;
78         }
79
80         virtual ~WrapperFactory(){}
81     };
82 }
83
84 #endif