Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / include / WrapperFactory.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 #ifndef _WRAPPER_FACTORY_H_
7 #define _WRAPPER_FACTORY_H_
8
9 #include <memory>
10 #include <OCApi.h>
11 #include "IClientWrapper.h"
12 #include "IServerWrapper.h"
13 #include <OutOfProcClientWrapper.h>
14 #include <InProcClientWrapper.h>
15 #include <OutOfProcServerWrapper.h>
16 #include <InProcServerWrapper.h>
17
18 namespace OC
19 {
20     // Interface to permit easier mocking/unit testing later
21     class IWrapperFactory
22     {
23     public:
24         typedef std::shared_ptr<IWrapperFactory> Ptr;
25
26         virtual IClientWrapper::Ptr CreateClientWrapper(PlatformConfig cfg) =0;
27         virtual IServerWrapper::Ptr CreateServerWrapper(PlatformConfig cfg) =0;
28         virtual ~IWrapperFactory(){}
29     };
30
31     // Class to create the client/server object!
32     class WrapperFactory : public IWrapperFactory
33     {
34     public:
35         WrapperFactory(){}
36
37         virtual IClientWrapper::Ptr CreateClientWrapper(PlatformConfig cfg)
38         {
39             switch(cfg.serviceType)
40             {
41             case ServiceType::InProc:
42                 return std::make_shared<InProcClientWrapper>(cfg);
43                 break;
44             case ServiceType::OutOfProc:
45                 return std::make_shared<OutOfProcClientWrapper>(cfg);
46                 break;
47             }
48                         return nullptr;
49         }
50
51         virtual IServerWrapper::Ptr CreateServerWrapper(PlatformConfig cfg)
52         {
53             switch(cfg.serviceType)
54             {
55             case ServiceType::InProc:
56                 return std::make_shared<InProcServerWrapper>(cfg);
57                 break;
58             case ServiceType::OutOfProc:
59               //  return std::make_shared<OutOfProcServerWrapper>(cfg);
60                 break;
61             }
62                         return nullptr;
63         }
64
65         virtual ~WrapperFactory(){}
66     };
67 }
68
69 #endif