NUGU SDK Linux  1.7.6
capability.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 SK Telecom Co., Ltd. All rights reserved.
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 #ifndef __NUGU_CAPABILITY_H__
18 #define __NUGU_CAPABILITY_H__
19 
20 #include <algorithm>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include <base/nugu_event.h>
28 #include <nugu.h>
29 
30 namespace NuguClientKit {
31 
47 class NUGU_API Capability;
48 
52 class NUGU_API CapabilityEvent {
53 public:
54  explicit CapabilityEvent(const std::string& name, Capability* cap);
55  virtual ~CapabilityEvent();
56 
61  std::string getName();
62 
67  std::string getDialogRequestId();
68 
73  std::string getMessageId();
74 
79  void setDialogRequestId(const std::string& id);
80 
85  void setType(enum nugu_event_type type);
86 
91  void setMimeType(const std::string& type);
92 
96  void forceClose();
97 
103  void sendEvent(const std::string& context, const std::string& payload);
104 
111  void sendAttachmentEvent(bool is_end, size_t size, unsigned char* data);
112 
113 private:
114  struct Impl;
115  std::unique_ptr<Impl> pimpl;
116 };
117 
121 class NUGU_API Capability : virtual public ICapabilityInterface {
122 public:
123  explicit Capability(const std::string& name, const std::string& ver = "1.0");
124  virtual ~Capability();
125 
130  void setNuguCoreContainer(INuguCoreContainer* core_container) override;
131 
135  void initialize() override;
136 
140  void deInitialize() override;
141 
146  void setSuspendPolicy(SuspendPolicy policy = SuspendPolicy::STOP) override;
147 
151  void suspend() override;
152 
156  void restore() override;
157 
163  void addEventResultCallback(const std::string& ename, EventResultCallback callback) override;
164 
169  void removeEventResultCallback(const std::string& ename) override;
170 
175  void notifyEventResult(const std::string& event_desc) override;
176 
183  void notifyEventResponse(const std::string& msg_id, const std::string& data, bool success) override;
184 
190  void addReferrerEvents(const std::string& ename, const std::string& dname);
191 
197  void addBlockingPolicy(const std::string& dname, BlockingPolicy policy);
198 
204  std::string getReferrerDialogRequestId(const std::string& ename);
205 
211  void setReferrerDialogRequestId(const std::string& dname, const std::string& id);
212 
217  void setName(const std::string& name);
218 
223  std::string getName() override;
224 
229  void setVersion(const std::string& ver);
230 
235  std::string getVersion() override;
236 
242  std::string getPlayServiceIdInStackControl(const NJson::Value& playstack_control);
243 
249  std::string getPlayServiceIdInStackControl(const char* payload);
250 
255  InteractionMode getInteractionMode(const NJson::Value& interaction_control);
256 
261  void preprocessDirective(NuguDirective* ndir) override;
262 
267  void cancelDirective(NuguDirective* ndir) override;
268 
273  void processDirective(NuguDirective* ndir) override final;
274 
280  void destroyDirective(NuguDirective* ndir, bool is_cancel = false);
281 
287 
295  std::string sendEvent(const std::string& name, const std::string& context, const std::string& payload, EventResultCallback cb = nullptr);
296 
303  void sendEvent(CapabilityEvent* event, const std::string& context, const std::string& payload, EventResultCallback cb = nullptr);
304 
312  void sendAttachmentEvent(CapabilityEvent* event, bool is_end, size_t size, unsigned char* data);
313 
322  bool getProperty(const std::string& property, std::string& value) override;
323 
332  bool getProperties(const std::string& property, std::list<std::string>& values) override;
333 
338  void setCapabilityListener(ICapabilityListener* clistener) override;
339 
345  void setCancelPolicy(bool cancel_previous_dialog, DirectiveCancelPolicy&& cancel_policy = { true }) override;
346 
356  bool receiveCommand(const std::string& from, const std::string& command, const std::string& param) override;
357 
363  void receiveCommandAll(const std::string& command, const std::string& param) override;
364 
370  virtual void parsingDirective(const char* dname, const char* message);
371 
376  virtual std::string getContextInfo();
377 
382  virtual void updateCompactContext(NJson::Value& ctx) override;
383 
389 
390 protected:
392  bool initialized = false;
393 
395  bool destroy_directive_by_agent = false;
396 
398  bool suspended = false;
399 
401  INuguCoreContainer* core_container = nullptr;
402 
404  ICapabilityHelper* capa_helper = nullptr;
405 
407  IPlaySyncManager* playsync_manager = nullptr;
408 
410  IFocusManager* focus_manager = nullptr;
411 
413  ISessionManager* session_manager = nullptr;
414 
416  IInteractionControlManager* interaction_control_manager = nullptr;
417 
419  IDirectiveSequencer* directive_sequencer = nullptr;
420 
422  IRoutineManager* routine_manager = nullptr;
423 
425  SuspendPolicy suspend_policy = SuspendPolicy::STOP;
426 
427 private:
428  struct Impl;
429  std::unique_ptr<Impl> pimpl;
430  std::map<std::string, EventResultCallback> event_result_cbs;
431 };
432 
437 } // NuguClientKit
438 
439 #endif
CapabilityEvent.
Definition: capability.hh:52
void setMimeType(const std::string &type)
Set mime type.
void sendEvent(const std::string &context, const std::string &payload)
Send event to server.
std::string getMessageId()
Get message id.
void sendAttachmentEvent(bool is_end, size_t size, unsigned char *data)
Send attachment event to server.
std::string getDialogRequestId()
Get dialog request id.
void forceClose()
Close event forcibly.
void setDialogRequestId(const std::string &id)
Set dialog request id.
void setType(enum nugu_event_type type)
Set event type.
std::string getName()
Get event name.
Capability.
Definition: capability.hh:121
void setReferrerDialogRequestId(const std::string &dname, const std::string &id)
Set referred dialog request id.
std::string getVersion() override
Get the capability version of the current object.
void notifyEventResult(const std::string &event_desc) override
Notify event result.
void sendAttachmentEvent(CapabilityEvent *event, bool is_end, size_t size, unsigned char *data)
Send attachment event to server.
void setVersion(const std::string &ver)
Set the capability version of the current object.
std::string getName() override
Get the capability name of the current object.
void sendEvent(CapabilityEvent *event, const std::string &context, const std::string &payload, EventResultCallback cb=nullptr)
Send event to server.
virtual void parsingDirective(const char *dname, const char *message)
Parsing directive and do the required action.
void cancelDirective(NuguDirective *ndir) override
Receive a directive cancellation from the Directive sequencer.
ICapabilityHelper * getCapabilityHelper()
Get ICapabilityHelper instance for using NuguCore functions.
std::string getPlayServiceIdInStackControl(const NJson::Value &playstack_control)
Get play service id which is managed by play stack control.
virtual std::string getContextInfo()
Get current context info.
void setNuguCoreContainer(INuguCoreContainer *core_container) override
Set INuguCoreContainer for using functions in NuguCore.
bool getProperties(const std::string &property, std::list< std::string > &values) override
It is possible to share own property values among objects.
void setSuspendPolicy(SuspendPolicy policy=SuspendPolicy::STOP) override
Set capability suspend policy.
void initialize() override
Initialize the current object.
std::string getPlayServiceIdInStackControl(const char *payload)
Get play service id which is managed by play stack control.
void setName(const std::string &name)
Set the capability name of the current object.
void removeEventResultCallback(const std::string &ename) override
Remove event result callback.
InteractionMode getInteractionMode(const NJson::Value &interaction_control)
Get interaction mode which is included in interactionControl.
std::string getReferrerDialogRequestId(const std::string &ename)
Get referred dialog request id.
NuguDirective * getNuguDirective()
Get directive received from Directive Sequencer.
void preprocessDirective(NuguDirective *ndir) override
Receive a directive preprocessing request from Directive sequencer.
bool receiveCommand(const std::string &from, const std::string &command, const std::string &param) override
Process command from other objects.
void notifyEventResponse(const std::string &msg_id, const std::string &data, bool success) override
Notify event response info.
void destroyDirective(NuguDirective *ndir, bool is_cancel=false)
Destroy directive received from Directive Sequencer.
std::string sendEvent(const std::string &name, const std::string &context, const std::string &payload, EventResultCallback cb=nullptr)
Send event to server.
virtual void updateCompactContext(NJson::Value &ctx) override
Update the compact context information of the capability agent.
void setCancelPolicy(bool cancel_previous_dialog, DirectiveCancelPolicy &&cancel_policy={ true }) override
Set directive cancel policy.
bool getProperty(const std::string &property, std::string &value) override
It is possible to share own property value among objects.
void setCapabilityListener(ICapabilityListener *clistener) override
Set the listener object.
void addEventResultCallback(const std::string &ename, EventResultCallback callback) override
Add event result callback for error handling.
void receiveCommandAll(const std::string &command, const std::string &param) override
Process command received from capability manager.
void suspend() override
Suspend current action.
void addReferrerEvents(const std::string &ename, const std::string &dname)
Add event name and directive name for referred dialog request id.
void processDirective(NuguDirective *ndir) override final
Receive a directive processing request from Directive sequencer.
void addBlockingPolicy(const std::string &dname, BlockingPolicy policy)
Add blocking policy for directive name.
void restore() override
Restore previous suspended action.
void deInitialize() override
Deinitialize the current object.
CapabilityHelper interface.
Definition: capability_helper_interface.hh:47
capability interface
Definition: capability_interface.hh:82
SuspendPolicy
Capability suspend policy.
Definition: capability_interface.hh:87
std::function< void(const std::string &, const std::string &, const std::string &, int, int)> EventResultCallback
Event result callback for error handling.
Definition: capability_interface.hh:100
capability listener interface
Definition: capability_interface.hh:60
IDirectiveSequencer.
Definition: directive_sequencer_interface.hh:94
IFocusManager.
Definition: focus_manager_interface.hh:128
InteractionControlManager interface.
Definition: interaction_control_manager_interface.hh:69
NuguCoreContainer interface.
Definition: nugu_core_container_interface.hh:44
IPlaySyncManager interface.
Definition: playsync_manager_interface.hh:96
IRoutineManager interface.
Definition: routine_manager_interface.hh:76
SessionManager interface.
Definition: session_manager_interface.hh:73
class NUGU_API Capability
Capability.
Definition: capability.hh:47
InteractionMode
Interaction Mode.
Definition: interaction_control_manager_interface.hh:40
struct _nugu_directive NuguDirective
Directive object.
Definition: nugu_directive.h:48
nugu_event_type
event types
Definition: nugu_event.h:48
BlockingPolicy.
Definition: directive_sequencer_interface.hh:52
Policy about canceling directives which are belong to the specific dialog id.
Definition: capability_interface.hh:46